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 became 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. In the root’s .bashrc I put this line (it makes it a lot safer afterwards):

export SUDO_HOME=$(eval "echo ~$SUDO_USER")

In the root’s .vimrc following code is added (you may need to add more paths):

if !empty($SUDO_HOME)
    set runtimepath+=${SUDO_HOME}/.vim/bundle/vundle,${SUDO_HOME}/.vim
    let $MYVIMRC=$SUDO_HOME.'/.vimrc'
    source $MYVIMRC
endif

When logging as root using a key, I put following at the beginning of the authorized_keys file:

environment="SUDO_USER=ondrej" ssh-rsa ...

This may require PermitUserEnvironment yes in your sshd configuration.

Categories: Missing Answers Tags: