Home > Missing Answers > How to use own vim configuration after sudo to shared account

How to use own vim configuration after sudo to shared account

Recently I become a fan of vim – and after storing my tuned dotvim on github, I found out, that I miss my configuration when I sudo to the root account. However, I’m not the only sudo user and I we have our own dotvim configuration. Here is a simple solution to be put into root’s .bashrc:

if [ -n "${SUDO_USER}" -a -d "/home/${SUDO_USER}/.vim" ]; then
alias vim="/usr/bin/vim --cmd \"set runtimepath+=/home/${SUDO_USER}/.vim\" -u /home/${SUDO_USER}/.vimrc"
fi

It took me quite a lot of googling to find the right combintation of $VIMRC, $VIMRUNTIME, $VIMINIT, $VIMHOME – and finally as you can see, none of those variables is used. Very usefull during debugging was to run vim with -V. to see where it looks for its configuration. And yes, I have tried putting the code to set the runtimepath to the .vimrc, but it would have to be conditional and this seems more clean.

Categories: Missing Answers Tags: