8

Lured in by the promise of evil-mode, I've been moonlighting in Emacs. It's a wild world with a mix of hairy lose-ends and astoundingly smart features. One feature I really like is a command called bury-buffer, which puts the current buffer way down at the bottom of the buffer-list and displays the previously active buffer in its place. By burying a buffer, it becomes the least likely candidate for other-buffer (like Vim's alternate-file on Ctrl-^).

So, I might be bouncing back and forth between buffer A and buffer B. Then, while I'm in B, I want check something in buffer C. I do, then I bury C, and I'm put back in B with A as my alternate-file. The same is true if I had deleted buffer C rather than burying it. Either action would put me back in my A/B workflow.

If I do the same in Vim, alternating between A and B, then from B open C, the buffer list shows C as active (%) and B as alternate (#). When I delete C, Vim returns me to B. But C is still the alternate-file, even though it no longer appears in the buffer list. If I hit Ctrl-^, it reopens C rather than taking me back to A.

Is there a way I can configure Vim so its alternate-file behavior would instead mark the most-recently used open buffer as the alternate instead of reviving deleted buffers? Is there a way to manipulate its concept of the alternate-file?

ivan
  • 1,450
  • 1
  • 11
  • 16

1 Answers1

7

I think you are looking for :help :keepalt:

$ vim a b       current buffer is 'a', no alternate file
:bn             current is 'b', alternate is 'a'
:b#             current is 'a', alternate is 'b'
:b#             current is 'b', alternate is 'a'
:keepalt e c    current is 'c', alternate is still 'a'
:keepalt bd     current is 'b', alternate is 'a'
:b#             current is 'a', alternate is 'b'
romainl
  • 40,486
  • 5
  • 85
  • 117
  • I was hoping there'd be an option I could set that would effect this behavior regardless how the file was opened/closed, but this is a good command to know about. Thanks. – ivan Oct 10 '16 at 22:36
  • 1
    Different workflow: stash your buffers in the arguments list with :args % #, edit whatever files you like, then restore with :last|N. – Antony Oct 16 '16 at 23:44