Utilize a different user's vimrc as well as vim folder

5,019

Solution 1

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

Solution 2

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.

Share:
5,019

Related videos on Youtube

xrfang
Author by

xrfang

Updated on September 18, 2022

Comments

  • xrfang
    xrfang over 1 year

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

    • Sven
      Sven over 11 years
      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.
    • Admin
      Admin over 11 years
      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.
    • Admin
      Admin over 11 years
      vim -u /home/b/.vimrc maybe ? ~ expands to the home directory of the current user, so /root for root, not /home
  • aLittleHelpBlease
    aLittleHelpBlease over 11 years
    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.
  • John Siu
    John Siu over 11 years
    Can you post your vimrc? I believe it is still path related.
  • aLittleHelpBlease
    aLittleHelpBlease over 11 years
    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
  • aLittleHelpBlease
    aLittleHelpBlease over 11 years
    Here is the same with syntax turned on. Sorry about that: pastebin.com/knkSeemX .
  • John Siu
    John Siu over 11 years
    Try vim -u /home/b/.vimrc. There are also discussion in following link: stackoverflow.com/a/7109871/1810391