Vim: Close All Buffers But This One

I was able to do this pretty easily like this:

:%bd|e#

Try this

bufdo bd

bufdo runs command for all buffers

http://vim.wikia.com/wiki/Run_a_command_in_multiple_buffers


You could use this script from vim.org:

http://www.vim.org/scripts/script.php?script_id=1071

Just put it to your .vim/plugin directory and then use :BufOnly command to close all buffers but the active one. You could also map it elsewhere you like in your .vimrc.

Source on Github (via vim-scripts mirror): https://github.com/vim-scripts/BufOnly.vim/blob/master/plugin/BufOnly.vim


If you don´t care the current one, is more simple to do something like (no script needing):

1,100bd