Temporary .vimrc

configurationvimvimrc

Is there a way to read a .vimrc file for only a single ssh session? That is, when I log in I perform some operation so that vim uses say /tmp/myvimrc until I log out?

I do not want to permanently overwrite the current .vimrc, I just need to use a different set of settings for the duration of my login every once in a while.

Best Answer

Suppose you have this other set of settings in /tmp/myvimrc. If my reading of man vim is correct you can start vim with this set of settings using the following:

$ vim -u /tmp/myvimrc

Thus, to make this an option for the rest of the session, I would create a function that sets this as an alias for vim. Thus, in bash I would put something like this in my .bashrc file:

function vimswitch {
    alias vim='vim -u /tmp/myvimrc'
}

Then, when I wanted my new vim settings, I would just run:

$ vimswitch

Note that I wouldn't store myvimrc in /tmp since this could easily be cleared out upon reboot. If you are using a shell other than bash this should still be possible, but the syntax could differ slightly.