11

I usually have multiple instances of vim running on the same machine. When I make a change to my vimrc I can just :source ~/.vimrc (with an easy mapping or an autocmd). But in order to have all running instances reflect the change I have to run that in each of them separately. Can I use the clientserver feature to tell all instances to reload my vimrc?

I would also be interested in solutions that don't use clientserver.

7

You can tell a Vim server to reload the vimrc file like so:

$ vim --servername MARTIN --remote-send '<Esc>:source $MYVIMRC<CR>' 

And you can get a list of all servers with:

$ vim --serverlist
MARTIN
CARPETSMOKER

Which can be combined with a for loop:

$ for s in $(vim --serverlist); do vim --servername "$s" --remote-send '<Esc>:source $MYVIMRC<CR>'; done

Since that's a lot of typing, you could put it in a shell script in ~/bin/reload-vimrc; you can of course also call it from within Vim:

:!reload-vimrc

If you're running Linux, and want to get really crazy, you could use inotifywatch from inotify-tools to monitor your vimrc file(s) for changes, and execute this automatically on every change (untested, example adapted from manpage)

$ inotifywatch -v -e modify -t 60 -r ~/.vimrc ~/.vim

I wouldn't recommend this, though ... If you accidentally save a file with a syntax error you could bork all your vim session...

-1

I don't know about clientserver, but since you said you were interested in other solutions I would recommend looking into this writeup about dotfiles from Github.

https://dotfiles.github.io

You obviously don't have to use Github, but the concepts are sound and seem to be widely used.

  • While I do think having your dotfiles under version control is awesome, I was specifically asking about instances of vim running on the same machine (I've updated the question). – xthrd Feb 3 '15 at 21:14
  • 1
    -1; This answer doesn't really have any bearing on the asked question. The question is about reloading vimrc, not managing vimrc. – Martin Tournoij Feb 6 '15 at 15:30
  • The original question prior to my answer did not make it clear he was talking about instances on the same machine. At the time my answer did address the question. – tgrosinger Feb 6 '15 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.