let's say currently there are two buffers in my vim session, and I want to close the current buffer which is under edit in order to switch the other buffer and edit it . using
:q
will quit the whole vim rather than a buffer . so my question is are there any commands can close the current buffer under editing and automatically switch to the next buffer in the buffer list .
Assuming the default backslash leader key, you can also press \bd to close (delete) the buffer in the current window (same as :Bclose ).
C-x k to kill the current buffer. C-x 0 to close the current window. C-x 1 to close every other window.
To save a file in Vim and exit, press Esc > Shift + ZZ. To exit Vim without saving, press Esc > Shift + ZX.
You can quit from all open files (buffers) by :qa or :qa! In vim. The exclamation mark means to force quit the edited unsaved file.
Just doing a
:bd
should do it.
Edit: You can delete specific buffers as well using this command.
Get a list of your current buffers by entering:
:ls
This will give you something like:
1 # "ap22_linux_build.sh.log" line 87
2 "httpd-2.2.14-2010011600-linux32-g.build_log" line 4207
3 %a "~/.bashrc" line 1
Take the relevant number and enter it before the bd command, so entering
: 2 bd
will delete the second buffer.
:bd (buffer delete) or :n (next)
The latter offers the advantage of being able to go back to the first file with :p (previous)
Theres also :bw which wipes the buffer as well. Eg. :bd will remove the buffer but you can get back to it if you hit ctrl-6.
I also really like bufexplorers 'd' key mapping in the buffer viewer, if your like me and get loads of buffers open its a quick way to go through and remove ones you dont need any more. http://www.vim.org/scripts/script.php?script_id=42
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With