Brett Stahlman wrote:

> Andy Wokula wrote:
> > Am 07.02.2010 17:16, schrieb Stahlman Family:
> >> Consider the following test sequence...
> >> :new
> >> :ls
> >> 1 #a "[No Name]" line 1
> >> 2 %a "[No Name]" line 1
> >> :hide
> >> :ls
> >> 1 %a "[No Name]" line 1
> >> 2 h "[No Name]" line 0
> >> :new somefile.txt
> >> :ls
> >> 1 #a "[No Name]" line 1
> >> 2 h "[No Name]" line 0
> >> 3 %a "somefile.txt" line 1
> >>
> >> As expected, the empty [No Name] buffer created with :new was hidden by
> >> the :hide command and remains in the buffer list. I can get it back in
> >> its own window by executing...
> >> :sb 2
> >>
> >> Now consider the following variation on the test sequence above...
> >> :new
> >> :ls
> >> 1 #a "[No Name]" line 1
> >> 2 %a "[No Name]" line 1
> >> :hide e somefile.txt
> >> :ls
> >> 1 a "[No Name]" line 1
> >> 2 %a "somefile.txt" line 1
> >>
> >> Notice that the [No Name] buffer that used to be buffer 2 is now gone,
> >> apparently replaced by somefile.txt. I can't possibly get it back. I
> >> know it was discarded (and not simply reassigned the name somefile.txt)
> >> because any buffer-local variables it contained are not accessible in
> >> the somefile.txt buffer.
> >>
> >> It seems to me that the 2 test cases above should produce similar
> >> results. In particular, I would expect that executing...
> >> :sb 2
> >> ...at the end of the second sequence would restore to its own window the
> >> [No Name] buffer hidden by...
> >> :hide e somefile.txt
> >>
> >> Is this a bug, or is the behavior described somewhere in the 
> >> documentation?
> >>
> >> Thanks,
> >> Brett Stahlman
> > 
> > This reminds me of :enew (where it's undocumented, too).
> > 
> > When the current buffer is unnamed and empty ('buftype' doesn't matter),
> > :enew will reuse its number.
> 
> Yes. I first noticed the issue when doing...
> :hide enew
> ...in an empty [No Name] buffer.
> 
> > 
> > What will get lost from the old buffer:
> > - buffer local variables
> > - undo history
> > (99% of unnamed and empty buffers will not have any of them)
> 
> Perhaps my case is unusual, but the :enew was used to create a scratch 
> buffer in the middle of a plugin load sequence, after a bunch of 
> buf-local variables had been created in the original buffer. I really 
> needed to go back to the original buffer (after testing something in the 
> scratch buffer), even if the original buffer happened to be an empty [No 
> Name] buffer.
> 
> > 
> > This is only what I checked, not a complete list.
> > 
> > I think Vim just tries to be smart and not waste buffer numbers ...
> > which isusually ok for me.
> 
> Perhaps so. If that's the case, though, why doesn't it reclaim one of 
> the empty [No Name] buffers in case 1 above? It seems inconsistent.

I don't know where it's documented, but when you do ":e file" while
editing an empty, unnamed buffer it re-uses that buffer.

This was done to avoid empty, unnamed buffers to appear quite often,
especially with the sequence ":new" ":e file".

An easy way to avoid the buffer being re-used is adding an empty line to
it (and setting 'nomodified').  You could give it a name, but you have
to make sure the name is unique.

-- 
hundred-and-one symptoms of being an internet addict:
201. When somebody asks you where you are, you tell them in which chat room.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

Reply via email to