How can I close all buffers in Vim except the one I am currently editing?
I put this in my .vimrc file
nnoremap <leader>ca :w <bar> %bd <bar> e# <bar> bd# <CR>
then your leader + ca
(close all) close all the buffers except the current one.
What it does is
:w - save current buffer
%bd - close all the buffers
e# - open last edited file
bd# - close the unnamed buffer
There's a plugin that does exactly this and a bit more!
Check out close-buffers.vim
Try this
bufdo bd
bufdo runs command for all buffers
http://vim.wikia.com/wiki/Run_a_command_in_multiple_buffers
I do this
:w | %bd | e#
My favorite if I just want my current buffer open and close all others.
How it works: first write current buffer's changes, then close all open buffers, then reopen the buffer I was currently on. In Vim, the |
chains the execution of commands together. If your buffer is up to date the above can be shortened to :%bd | e#
Note: As mentioned in the comments, this closes windows and not buffers.
By using
:on[ly][!]
and
:h only
How about just:
ctrl-w o
(thanks to https://thoughtbot.com/blog/vim-splits-move-faster-and-more-naturally)