Unable to close many buffers by one command in Vim

Viewed 14025

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?

9 Answers

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.

:qall or :qa will close all windows

: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

That doesn't save the buffers though. Maybe :wqall! :xall! is a little better.

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

Related