How to keep the vim environment when ssh-ing between accounts on the same machine


I frequently move between accounts on my machine using SSH. Multiple different projects having their own development and production accounts. Is it possible to keep my vim environment the same between accounts?

I've tried playing with the VIMRUNTIME, VIM, and vimrc settings to define one shared location for the settings but that doesn't seem to work. The settings are sort of picked up but others are not. For example line numbers will be turned on, tabbing is enabled, key-bindings are there but the color scheme is not or the file-type doesn't seem to be properly detected for files.

Best Answer

Setting $VIMRUNTIME will override the loading of system-wide shared configuration, which is usually not what you want. And no, you can't specify more than one path in that environment variable, so it's not terribly useful (the docs hint that you shouldn't really be setting it directly, probably for that reason).

Instead, add to runtimepath from within your .vimrc:

set runtimepath+=/home/ACCOUNT/.vim

Then, use the environment variable VIMINIT to tell vim to source your (single shared) .vimrc on startup:

VIMINIT='so /home/ACCOUNT/.vimrc'

Now you'll have shared your .vimrc and your .vim directory and its contents, and you'll still have whatever system defaults are configured, which should be exactly what you need.