Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: Close All Buffers But This One

Tags:

vim

People also ask

How do I close only one buffer in Vim?

Vim has two commands for closing a buffer: :bdelete and :bwipeout . The former removes the file from the buffer list, clears its options, variables and mappings. However, it remains in the jumplist, so Ctrl-o takes you back and reopens the file.

How do I close all open files in Vim?

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.


Try this

bufdo bd

bufdo runs command for all buffers

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


I was able to do this pretty easily like this:

:%bd|e#

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