Unable to close many buffers by one command in Vim
VimVim Problem Overview
I use Vim in Screen. I run the command
vim <bigFolder>
I am in stuck, since it does not make sense to close each buffer by
:q
How can you close all active buffers in Vim, by one command inside Vim?
Vim Solutions
Solution 1 - Vim
The :bufdo
command lets you execute a command on all buffers. In this case, you want to run :bufdo bdelete
to close all open buffers in one go.
Solution 2 - Vim
:qall
or :qa
will close all windows
Solution 3 - Vim
:%bd(elete)
I think this is what you asking for
Solution 4 - Vim
:on
will close all buffers except the one you are currently editing (the cursor is inside this buffer).
:on!
will also close modified buffers but these will become hidden buffers.
:ls
will lists all the buffers with their status (hidden, ...)
Some help:
:h only
:h hidden-buffer
:h ls
Solution 5 - Vim
:on
does NOT close any buffers.
It only closes the other windows.
Solution 6 - Vim
This isn't exactly what you asked for, but the following may give a desired outcome. It:
-
makes the current tab the only open tab (
:tabo
) -
makes the window in the tab the only open window (
:only
) -
displays the first buffer in the open window (
1 b
) -
deletes buffers numbered 2 to 2000 (
2,2000bd
):tabo | :only | 1 b | 2,2000 bd
Should you have more than 2000 buffers open, adjust accordingly.
It you simply want to delete all buffers, 1,2000bd
should do the job, but note that new, empty buffers will be created for all open tabs and windows.
Solution 7 - Vim
That doesn't save the buffers though. Maybe :wqall! :xall! is a little better.
Solution 8 - Vim
If you happen to get VIM completely stuck you should still be able to kill it from outside VIM.
- If you're able to suspend VIM with CTRL+Z, then you can kill it with
kill %vim
- If you can't suspend VIM you should be able to find its pid using
ps
. The you can kill it:
$ ps -f -C vim
UID PID PPID C STIME TTY TIME CMD
nfellman 27273 7473 0 Jun24 pts/15 00:00:00 /nfs/iil/home/nfellman/vim/bin/vim a.pl
nfellman 37213 23747 0 Jun23 pts/15 00:00:00 /nfs/iil/home/nfellman/vim/bin/vim b.pl
So if I want to kill the VIM that's editing a.pl
you can do:
kill -9 27273
This should work even inside screen
Solution 9 - Vim
:q!
always works for me.