tags:

views:

102

answers:

2

Here's my situation. I have a bunch of vim processes open. Rather than go through one by one and save/quite (:x!) I'd like to send all of the processes a signal - say USR1 - and instead of having it create a recovery .swp file, I'd like it to save the file and exit normally.

Possible?

+1  A: 

I've never tried to handle signals in vim. I don't know if it can be done. Here is one possible alternative:

Option: Use just one vim process

Perhaps instead of opening a ton of vim processes, you can open a bunch of tabs in gvim (or vim). That way, when you want to quit you can do :wqa (write and quit all).

It is easier to open tabs in vim if you do the following in your vimrc file:

:map <C-Insert> :tabnew<C-M>
:map <C-Delete> :tabclose<C-M>
:map <C-PgUp> :tabprev<C-M>
:map <C-PgDown> :tabnext<C-M>

The bindings above will allow Ctrl-insert and Ctrl-delete to open and close tabs, and Ctrl-pgup/pgdown will move between tabs much like firefox.

If you wanted those bindings to work in insert mode as well, you could do something like this in your vimrc file

:imap <C-Insert> <C-o>:tabnew<C-M>
:imap <C-Delete> <C-o>:tabclose<C-M>
:imap <C-PgUp> <C-o>:tabprev<C-M>
:imap <C-PgDown> <C-o>:tabnext<C-M>
Kimball Robinson
This would work, but in my case I tend to have 4-5 screen sessions open on the same server (for different projects). Each screen session has a possible 7 vim sessions open...
Philip Hallstrom
+3  A: 

It's not quite as simple as just sending every vim process a signal, but you can get pretty close to what you want using vim's client/server features:

:help remote.txt

(You'll need a version of vim that's been compiled with the +clientserver option.)

Here's an example from the vim help:

vim --servername BLA --remote-send '<C-\><C-N>:wqa<CR>'    

That sends commands to the vim instance running as remote server "BLA", telling it to save all files and exit.

Since you're running multiple vim instances, you'll probably want to use the --serverlist option to get a list of all registered server instances, which you can then iterate over to send the save-and-exit command to each one.

Bill Odom