Resetting Buffers in Vim


Resetting Buffers in Vim



Is it possible to reset the alternate buffer in a vim session to what it was previously?

By alternate buffer, I mean the one that is referred to by #, i.e. the one that is displayed when you enter cntl-^.

Say I've got two files open main.c and other.c and :ls gives me:

  1 %a   "main.c"              lines 27   2 #    "other.c"             lines 56 

Say I open another file, e.g. refer.c, :ls will now give me:

  1 %a   "main.c"              lines 27   2      "other.c"             lines 56   3 #    "refer.c"             lines 125 

If I delete the buffer containing refer.c, :ls now shows:

  1 %a   "main.c"              lines 27   2      "other.c"             lines 56 

But if I do a cntl-^, refer.c will be displayed again!

Is there some way to get vim to reset the alternate buffer back to what it last was automatically? A "history" of alternate buffers?

Or am I stuck with doing a :2 b to reload other.c into the alternate buffer?

Or maybe there is a good reason for this behaviour?




How do I get Vim to highlight matching parenthesis?

1:



Tab key == 4 spaces and auto-indent after curly braces in Vim
In this case, "alternate" just means "previous".


Indent multiple lines quickly in vi
So, yes, :b2 (or 2 ctrl-6) is probably the easiest way to change which two buffers will be toggled by ctrl-6..
how do I add a font in gVim on windows system
Also, take a look at the :keepalt command..
vim — How to read range of lines from a file into current buffer


What's the best thing you've done with vim that helped your programming?


70 out of 100 based on 70 user ratings 670 reviews