Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm getting thrown into an IDE war at the office, where multiple users have root access on our servers, and like to have everything their own way with VIM. Unfortunately, we have our servers locked down enough to where if you want to do anything, you need to have root access. Obviously (although this is obviously frowned upon), we get tired of typing sudo before each command we type, which would require that we constantly type in our wonderfully complex passwords that are mandated on us over and over again, so naturally we all just execute the sudo su - command upon login to avoid all of this.

Of course, when it comes to VIM and custom .vimrc files, we are often times stepping on someone else's custom .vimrc file, and we have some whacked out functionality in these files that users have that may overwrite functionality that we have no idea about, much less have the patience to learn either.

When as root on a linux box, is there any way for all of us to still maintain our .vimrc file without having to overwrite the file over and over again every time someone wants to use VIM? Ideally, we have many virtual machines all with VIM installed, so a universal solution across all servers would be best, and we do have our Microsoft Windows user specific home directories mounted on the servers under /home/username.

Any recommendations for accommodating this?

share|improve this question

migrated from stackoverflow.com Jun 24 '11 at 23:17

This question came from our site for professional and enthusiast programmers.

2 Answers 2

up vote 2 down vote accepted

I can think of 3 options. The first one is probably the simplest.

  1. call vim like the following vim -u /path/to/custom/.conifg fileToEdit
    Man Entry:

    -u {vimrc}  Use  the commands in the file {vimrc} for initializations. 
    

    All the other initial‐ izations are skipped. Use this to edit a special kind of files. It can also be used to skip all initializations by giving the name "NONE". See ":help initial‐ ization" within vim for more details.

      -U {gvimrc} Use the commands in the file {gvimrc} for GUI
    

    initializations. All the other GUI initializations are skipped. It can also be used to skip all GUI initializations by giving the name "NONE". See ":help gui-init" within vim for more details.

  2. sudo -i as was specified by @knittl User-unique .vimrc file for servers as root user

  3. lastly, How to share one vimrc file among multiple clients? which suggests keeping a set of personal config files in git or another version control system. Therefore each user could checkout what they need upon log in. Also, you can keep a history of your changes. version control is never a bad idea.
share|improve this answer
    
Thanks, sudo -i along with some crafty bash scripting and svn did it! –  Scott Jun 25 '11 at 0:06

use sudo -i to get to a root shell with the current user's environment still loaded.

man sudo:

The -i (simulate initial login) option runs the shell specified in the passwd(5) entry of the user that the command is being run as. The command name argument given to the shell begins with a - to tell the shell to run as a login shell. sudo attempts to change to that user's home directory before running the shell. It also initializes the environment, leaving TERM unchanged, setting HOME , SHELL , USER , LOGNAME , and PATH , and unsetting all other environment variables. Note that because the shell to use is determined before the sudoers file is parsed, a runas_default setting in sudoers will specify the user to run the shell as but will not affect which shell is actually run.

share|improve this answer
    
+1 for the sudo -i ...much better than a wikipedia link to sudo. –  matchew Jun 24 '11 at 18:10
2  
If the question is, "How can multiple users run vim as root and still use their unique vimrc", this answer is simply wrong. –  sciurus Sep 16 '12 at 2:23
    
Sorry, accidentally posted early. 'sudo -i' is almost exactly equivalent to 'su -'. It resets the current users environment. In the portion of the manpage quoted, it explicitly states that 'sudo -i' sets HOME, so vim will read /root/.vimrc. –  sciurus Sep 16 '12 at 2:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.