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
Thank you so much for this!
Using the sudoedit command works better. creates a temporary file that you edit with regular perms /configs then copies to intended destination when you write it.
@Pete: sudoedit might me a good thing, however, I spent all my time logged in as root.
[…] sudoでvimを触りたい時はsudoeditコマンドを使うといいらしい。この中で:shellとかしてもroot shellに出ていけない特徴があるが、これはいいことあり悪いことありなので、sudo vimした時にでも自分のvimrcを使うにはBrablc.com » How to use own vim configuration after sudo to shared accountを参考にしつつ/root/.vimrcに以下のように。 […]