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.

3 Answers 3


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.

  • 1
    nice! That's what I call going the whole 9 yards. Nov 18, 2010 at 18:07

You can use the VIMINIT environment variable to override the use of the usual .vimrc while keeping other parts of the initialization process. VIMINIT should be set to one or more ex-style commands (“colon” commands; use pipe (|) to separate multiple commands), not just the path to a different initialization file.

VIMINIT='so /tmp/myvimrc'; export VIMINIT

vim whatever # uses /tmp/myvimrc, not ~/.vimrc

The main difference from using -u is that VIMINIT will still allow the other parts of initialization process to be used (e.g. system vimrc, evim.vim (if applicable), et cetera).

  • 2
    To automatically setting VIMINIT variable while logging via ssh you could use file ~/.ssh/environment. This file could be used only for setting environment variables, so only entry you should add is: VIMINIT='so /tmp/myvimrc'. This file is processed only when in sshd configuration option PermitUserEnvironment is set to yes, so you should test on your own if it works for you or ask your administrator if it is turn on.
    – pbm
    Nov 18, 2010 at 21:46

When you log in via ssh, ssh sets variable $SSH_CONNECTION. Your .bashrc could check for this var and if it is set sets alias that you want:

if [ -n "$SSH_CONNECTION" ]
        alias vim='vim -u /tmp/myvimrc'
  • +1 for SSH_CONNECTION tip
    – anishsane
    Feb 26, 2013 at 12:27

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.