Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid Vim keeping closed buffers open in the background

Tags:

vim

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".

like image 489
tobyS Avatar asked Apr 11 '13 09:04

tobyS


People also ask

How do I open a buffer in a new window in Vim?

The above command will open all buffers in a new window as follows: You can also open buffers in vertical window orientation using the following command on vim: : vertical ball. To open a particular buffer in a new window, for this purpose, issue the following command on Vim: : sbuffer.

How do I open a buffer in a new window?

You can also open buffers in vertical window orientation using the following command on vim: To open a particular buffer in a new window, for this purpose, issue the following command on Vim: You can also use the shortcut for this purpose. Type buffer number, then you will press ctrl w^.

How do I Close a buffer in Linux terminal?

Assuming the default backslash leader key, you can also press \bd to close (delete) the buffer in the current window (same as :Bclose ). Like the :bdelete command, :Bclose will fail if the buffer has been modified.

How to open a file in Vim command line editor?

If you open a file for editing, then it automatically creates a buffer, and each file will remain accessible until you close the Vim. Press ‘Ctrl + Alt + t’ to open the terminal. Now, you will access the Vim command-line editor using the following command:


2 Answers

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.

like image 63
Quinn Strahl Avatar answered Dec 15 '22 00:12

Quinn Strahl


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.

like image 37
guessimtoolate Avatar answered Dec 14 '22 23:12

guessimtoolate