Here's my situation. I have a bunch of vim processes open. Rather than go throu开发者_如何学Gogh 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?
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.
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>
I just wanted to add that you can get make
to run in the background asynchronously by using the following
nnoremap <leader>m : call setqflist([]) \| cclose \| silent execute ":! (make &>~/.vim/cpperr \|\| vimx --servername DEFAULT --remote-send '\ <C-\\>\<C-N\>:cgetfile ~/.vim/cpperr\<CR\>')&" \| redraw!<CR>
For this to work you must open your files using
vim --servername DEFAULT --remote-silent FILE..
I actually have that set as an alias to vim in my bashrc.
精彩评论