Reputation: 870
After doing a complete re-setup of my Vim environment using various standard extensions there is one behavior that annoys me quite much:
When I open a file in a split window and close that window again (":wq") Vim seems to keep the file buffer open in the background. When I now try to open the file in a different shell tab in a new Vim instance, the swap file still exists, what keeps me from editing the file.
I suppose there is a setting which makes Vim keep buffers open but hidden when I close the split, but I could not find out which one it is. What I actually desire is, that Vim really closes the buffers when I close the splits, so that I can open the corresponding files again in a parallel Vim session.
What I expect is, that the buffer is closed as soon as the last window showing it is closed via ":q".
Upvotes: 7
Views: 3371
Reputation: 1818
Check the value of the hidden
option using :set hidden?
. By default, vim has this set to nohidden
, which should produce the behaviour you're asking for; buffers are unloaded when they become abandoned (meaning no windows are displaying them). It's possible that this setting got set to hidden
, which causes the behaviour you're experiencing; buffers become hidden when abandoned.
Do :help 'hidden'
for more information.
Upvotes: 10
Reputation: 42198
I am not sure how you are closing a split, for example using CtrlWCtrlo in the other window or CtrlWCtrlq, but I don't think this is supposed to close the buffer as well. Spliting is only a window management method, not a a buffer management one.
If in a split, you want to close a buffer and its window, why don't you use :bd
? It will explicitly close the buffer.
Upvotes: 0
Reputation: 8632
I think you're confusing buffers with windows. A good explanation of the difference can be found here.
I'd also suggest this read. It has a script example that closes buffers without closing the window, which should be the effect you described.
Cheers, I hope that helps.
Upvotes: 2