I'd like to automatically set my Vim preferences on the root account, when I use it (throught a
sudo bash or
sudo su-like command), without changing the default configuration of the root account (because it's a shared account), and without having to use a lot of keystrokes to do this (I have to switch often).
To complicate things, our home directories are not available when in root mode (they are NFS-mounted, and, for security purposes, root isn't allowed to see inside, as root can be most anybody)
So, for now, I've put a nice little bundle of scripts in a subdirectory under /tmp, which happens to be readable and writable both under my non-root and under the root accounts.
Now, I've written a tiny script to allow me to connect as root with this slightly longer command (it works):
exec sudo bash --init-file /tmp/MY_DIR/MY_BASH_CONFIG_FILE
MY_BASH_CONFIG_FILE, I put a lot of things, mostly environment variable definitions, along with
source /root/.bashrc (in order to build from the usual root config, not from scratch).
Now, after all this exposition, let's get to the heart of the problem:
I've looked at Vim's man page, and found a
-u FILE option. However, this option will ONLY load the given file, and bypass any other Vim configuration file.
Which means that when I tried
alias vi=vim -u MY_DIR/MY_TMP_VIMRC, I would get a broken Vim, with arrow keys no longer working as intended, etc.
I've also tried merely naming the file
vimrc in my
/tmp subdir, and using in the bash config file the line
export VIM='MY_TMP_SUBDIR'. However, it still doesn't load the
Here are the files loaded when I run Vim as my unprivileged user (as given by the
scriptnames Vim command):
1: /etc/vimrc 2: /usr/share/vim/vim74/syntax/syntax.vim 3: /usr/share/vim/vim74/syntax/synload.vim 4: /usr/share/vim/vim74/syntax/syncolor.vim 5: /usr/share/vim/vim74/filetype.vim 6: /usr/share/vim/vimfiles/ftdetect/puppet.vim 7: /usr/share/vim/vim74/ftplugin.vim 8: ~/.vimrc 9: /usr/share/vim/vim74/plugin/getscriptPlugin.vim 10: /usr/share/vim/vim74/plugin/gzip.vim 11: /usr/share/vim/vim74/plugin/matchparen.vim 12: /usr/share/vim/vim74/plugin/netrwPlugin.vim 13: /usr/share/vim/vim74/plugin/rrhelper.vim 14: /usr/share/vim/vim74/plugin/spellfile.vim 15: /usr/share/vim/vim74/plugin/tarPlugin.vim 16: /usr/share/vim/vim74/plugin/tohtml.vim 17: /usr/share/vim/vim74/plugin/vimballPlugin.vim 18: /usr/share/vim/vim74/plugin/zipPlugin.vim 19: /usr/share/vim/vim74/scripts.vim 20: /usr/share/vim/vim74/syntax/conf.vim 21: /usr/share/vim/vim74/ftplugin/conf.vim
Now, here's what I get, running Vim as root:
1: /etc/vimrc 2: /usr/share/vim/vim74/syntax/syntax.vim 3: /usr/share/vim/vim74/syntax/synload.vim 4: /usr/share/vim/vim74/syntax/syncolor.vim 5: /usr/share/vim/vim74/filetype.vim 6: /usr/share/vim/vim74/ftplugin.vim 7: /usr/share/vim/vim74/plugin/getscriptPlugin.vim 8: /usr/share/vim/vim74/plugin/gzip.vim 9: /usr/share/vim/vim74/plugin/matchparen.vim 10: /usr/share/vim/vim74/plugin/netrwPlugin.vim 11: /usr/share/vim/vim74/plugin/rrhelper.vim 12: /usr/share/vim/vim74/plugin/spellfile.vim 13: /usr/share/vim/vim74/plugin/tarPlugin.vim 14: /usr/share/vim/vim74/plugin/tohtml.vim 15: /usr/share/vim/vim74/plugin/vimballPlugin.vim 16: /usr/share/vim/vim74/plugin/zipPlugin.vim 17: /usr/share/vim/vim74/scripts.vim
I've spaced some lines for readability:
As unprivileged used, I see that the
~/.vimrc file is loaded, but not when I run as root (even though the Vim environment variable is exported, and points to the tmp dir, which is readable, and contains a
vimrc file, which is readable too)
Also, the end lines (19 to 21 in user mode, or line 17 in root mode) appear only when using Vim on a file (if I type
vi, and then ask for the scriptnames on the title screen, I don't get them. However, if I type
vi SOMEFILE, then they appear). I'm not sure that's relevant.
Does anyone have an idea as to what I should do to get out of this predicament ? I'll be happy to provide more info, if needed, but I fear this post might already be too long...