Linux – Utilize a different user’s vimrc as well as vim folder

linuxvimvimrc

First of all, to prevent an X/Y Problem, I'll just state that what I really want is:

  1. Run vim as the root user.
  2. Instruct vim to use my nice pretty color scheme and all my plugins.
  3. Do all this without contaminating the /root/.vimrc or the /root/.vim folder.
  4. Do all this without running sudo vim hopefully…

I have my own account on each linux server with the following two files.

  • /home/b/.vim
    • My folder with my plugins etc.
  • /home/b/.vimrc
    • My dot vimrc file

Here is my first try running with my custom vim settings:

vim -u ~b/.vimrc
Error detected while processing /root/.vimrc:
line   33:
E185: Cannot find color scheme railscasts
line   82:
E117: Unknown function: ...
Press ENTER or type command to continue

However, my .vimrc file is searching for a plugin which only exists in my /home/b/.vim folder. Up until now I have always copied my own /home/b/.vim folder to the root user's area like so:

cp -r /home/b/.vim /root

But unfortunately this contaminates the root account's home folder, and I want to stop doing that (if possible). Can anyone tell me an environment variable, or any trick at all, to run with my own COMPLETE vim environment (including my plugins, etc.) without contaminating root?

Any help is greatly appreciated.

PS – I have gone through the info vim documentation and tried setting VIMRUNTIME VIMRC and other environment variables. They didn't help me, perhaps I was doing something wrong…?

Best Answer

You can add your .vim runtimepath on top of your .vimrc file:

:set runtimepath=/home/b/.vim,$VIMRUNTIME

This makes vim search for plugins, colors etc. in /home/b/.vim first and then in the standard location (for example /usr/share/vim/vim72/ in debian squeeze).

I'm using this together with an alias vim='vim -u /home/b/.vimrc'.

Related Question