Start Vim as my user with root privileges
Instead of sudo vim /etc/rc.conf
use sudoedit /etc/rc.conf
or sudo -e /etc/rc.conf
. You may need to set the EDITOR environment variable to vim. This will run vim itself as the normal user, using your normal configuration, on a copy of the file which it will copy back when you exit.
You can use -u
to tell vim which rc file to load. e.g.
sudo vim -u ~user/.vimrc /etc/rc.conf
if typing that every time you need to do it is tedious, make an alias:
alias sudovim='sudo vim -u ~user/.vimrc'
Note that vim -u
may cause plugins or called rc files to fail if they load other files relative to $HOME - $HOME is now root's home dir, not the user's. This can be solved with e.g. symlinks in root's home dir or by hard-coding absolute paths.