Linux – Use another user’s .vimrc and .vim/

linuxrootvim

I know that I can :source /path/to/some/.vimrc to load my user's .vimrc when running as root, but how can I use the entire .vim/ directory as well? Is there a startup option for using /home/user/.vim/ that I can set up as an alias?

And where in the fine manual would I have found this information if I had know what to look for. A simple :help .vim or :help .vimrc did not find the information regarding using the entire .vim/ direcotry (-U is only for the .vim file).

Thanks.

Best Answer

use the environment variable VIMINIT to point to the right .vimrc and VIMRUNTIME to point to the right .vim-directory. you can do this via env:

$> env VIMINIT=/home/user/.vimrc VIMRUNTIME=/home/user/.vim/ vim

$> VIMINIT='let $MYVIMRC = expand('\''~user'\'') . '\''/.vimrc'\''|source $MYVIMRC' vim -c 'set runtimepath=~user/.vim,/var/lib/vim/addons,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,/var/lib/vim/addons/after,~user/.vim/after'

as always: if thats too long to type, create a shell-function or a shell-alias.

to read more about how vim launches and what happens behind the scenes, read :help initialization.

Related Question