I open several files in Vim by, for example, running
vim a/*.php
which opens 23 files.
I then make my edit and run the following twice
:q
which closes all my buffers.
How can you close only one buffer in Vim?
I open several files in Vim by, for example, running
vim a/*.php
which opens 23 files.
I then make my edit and run the following twice
:q
which closes all my buffers.
How can you close only one buffer in Vim?
If this isn't made obvious by the the previous answers:
:bd will close the current buffer. If you don't want to grab the buffer list.
Check your buffer id using :buffers
you will see list of buffers there like
1 a.php
2 b.php
3 c.php
if you want to remove b.php from buffer
:2bw
if you want to remove/close all from buffers
:1,3bw
Use:
:ls - to list buffers:bd#n - to close buffer where #n is the buffer number (use ls to get it)Examples:
to delete buffer 2:
:bd2
If you want to close a buffer without destroying your window layout (current layout based on splits), you can use a Plugin like bbye. Based on this, you can just use
:Bdelete (instead of :bdelete)
:Bwipeout (instead of :bwipeout)
Or just create a mapping in your .vimrc for easier access like
:nnoremap <Leader>q :Bdelete<CR>
From the plugin's documentation:
- Close and remove the buffer.
- Show another file in that window.
- Show an empty file if you've got no other files open.
- Do not leave useless [no file] buffers if you decide to edit another file in that window.
- Work even if a file's open in multiple windows.
- Work a-okay with various buffer explorers and tabbars.
From the plugin's documentation:
Vim has two commands for closing a buffer:
:bdeleteand:bwipeout. The former removes the file from the buffer list, clears its options, variables and mappings. However, it remains in the jumplist, soCtrl-otakes you back and reopens the file. If that's not what you want, use:bwipeoutor Bbye's equivalent:Bwipeoutwhere you would've used:bdelete.
How about
vim -O a a
That way you can edit a single file on your left and navigate the whole dir on your right... Just a thought, not the solution...