How to close all files opened by different vim instances.

1,289 views
Skip to first unread message

Forest Wang

unread,
Mar 17, 2011, 4:08:22 AM3/17/11
to vim...@googlegroups.com
All,

Say, in a terminal, I opened many files by invoking vim or gvim program many times, like:

vim a&
vim b&
vim c&
...

Than I realized I need to close all of them. So I had to close them one by one:

%1 and :qa!
%2 and :qa!
...

Is there a better way to close all files by issuing one command or one script?

Thanks.
BR
Wang, Mengjia

Ivan Krasilnikov

unread,
Mar 17, 2011, 7:14:10 AM3/17/11
to vim...@googlegroups.com, Forest Wang

Yes - "killall vim".

Christian Brabandt

unread,
Mar 17, 2011, 7:39:22 AM3/17/11
to vim...@googlegroups.com

This is more a shell specific question and not vim specific (so
there might be better ways with your prefered shell).
This will also kill vim jobs, that have not been opened that way.
Also killall on unix, does what it says. It sends a signal to all jobs
and works differently then on linux (just pointing out the obvious,
this might be confusing to someone).

But I admit, killall was also my first guess to the problem.

regards,
Christian

ZyX

unread,
Mar 17, 2011, 11:31:22 AM3/17/11
to vim...@googlegroups.com
Reply to message «How to close all files opened by different vim instances.»,
sent 11:08:22 17 March 2011, Thursday
by Forest Wang:

<...>


> vim c&
> ...
>
> Than I realized I need to close all of them. So I had to close them one by
> one:
>
> %1 and :qa!
> %2 and :qa!
> ...
>
> Is there a better way to close all files by issuing one command or one
> script?

If you are on zsh, you could use the following script:

emulate -L zsh
for job in ${(k)jobtexts[(R)vim*|view*]} ; do
kill -TERM "${${(s.=.)${(@s.:.)jobstates[$job]}[3]}[1]}"
# For unknown reason kill -TERM handling is delayed
# until foregrounding, so doing it here. `kill -KILL' is not
# though
%$job
endfor
Note that you could put this into function in ~/.zshrc, but you can't put it
into separate script that will run in another process.

Original message:

signature.asc

Forest Wang

unread,
Mar 18, 2011, 2:17:49 AM3/18/11
to vim...@googlegroups.com
Thanks for all of your help.

For this problem, I think kill is not a choice. Because I want all of the vim instances save or simply quit without save. And I realized things would be done easily if there is a vim server. Thanks Google again. I found this:
http://ajayfromiiit.wordpress.com/2009/10/21/server-and-client-mode-in-vim/
and
http://vimdoc.sourceforge.net/htmldoc/remote.html

Still, this is not exactly what I am looking for, but it seems a handy script can be created to do a similar work.

What I need is: One vim server manages one or more vim instances which may be lunched within different windows/terminals.

Thanks.
BR
Wang, Mengjia





2011/3/17 ZyX <zyx...@gmail.com>
Reply all
Reply to author
Forward
0 new messages