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...?

  • It's a better fit on U&L, IMHO. Please don't ask a new question there but either wait for 5 users to migrate the question or flag it for mod attention.
    – Sven
    Jan 18, 2013 at 19:33
  • Okay I understand. I have the U&L page up, but I won't take any action right now. I was going to post it there but I saw the tags on Server Fault have vim and vimrc in the tags auto-complete, so I figured I'll give Server Fault a try first.
    – Bryan Harris
    Jan 18, 2013 at 19:45
  • vim -u /home/b/.vimrc maybe ? ~ expands to the home directory of the current user, so /root for root, not /home
    – zecrazytux
    Jan 18, 2013 at 20:04

4 Answers 4


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'.


I'm not sure what you mean by pollute but if you mean just not having duplicated files you can create a symbolic link. That's the way I keep my vim settings the same across different users.

I have .vimrc and .vim folders in /usr/local/etc/vim_settings, owned by root but readable for everyone else. Then for each user I do the following:

ln -s /usr/local/etc/vim_settings/vimrc /home/user/.vimrc ln -s /usr/local/etc/vim_settings/vim /home/user/.vim

The directory is technically "clean" that way and its simple enough to setup. I actually do this for a number of configuration files so when I move to a new system I simply copy my /usr/local/etc/ folder to the new machine and set up the links.


If this is just about an occasional edit of a config file here and there, I would launch Vim under my user account, and use the :write !sudo tee % trick, preferably in the form of the robust SudoEdit.vim - Edit Files using sudo or su or any other tool plugin.


My bet is your /home/b/.vimrc plugin path is relative to home directory. When you login as root, those path become relative to /root instead of /home/b. You should be able to modify that manually to absolute path.

  • I am sorry but I said plugins instead of color schemes... My fault, how can I place a full path to a color scheme? I'm going to start reading through documentation to see if maybe I can figure it out.
    – Bryan Harris
    Jan 18, 2013 at 20:16
  • Can you post your vimrc? I believe it is still path related.
    – John Siu
    Jan 18, 2013 at 20:19
  • I did this: export VIM=/home/b/.vim Now running vim errors about not finding a file which is normally in /usr/share/vim or someplace like that. Error detected while processing /root/.vimrc: line 13: E484: Can't open file /home/b/.vim/syntax/syntax.vim Press ENTER or type command to continue I put my vimrc on pastebin. I found this vimrc from github somewhere and then commented some of the lines. Sorry if it's hard to read. pastebin.com/0WNqggc6
    – Bryan Harris
    Jan 18, 2013 at 20:34
  • Here is the same with syntax turned on. Sorry about that: pastebin.com/knkSeemX .
    – Bryan Harris
    Jan 18, 2013 at 20:37
  • Also just fyi, I got the idea for setting the VIM environment variable from here: stackoverflow.com/questions/5453488/… . Not sure if that was the best way for me to get what I wanted.
    – Bryan Harris
    Jan 18, 2013 at 20:38

You must log in to answer this question.