views:

179

answers:

1

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?

+7  A: 

In this case, "alternate" just means "previous". So, yes, :b2 (or 2 ctrl-6) is probably the easiest way to change which two buffers will be toggled by ctrl-6.

Also, take a look at the :keepalt command.

graywh