I’m looking for a way to always start Vim as a sudo using -E “preserve environment” flag. Running sudo with this flag allows Vim to load .vimrc file and all themes/shortcuts.
I tried to write a .bashrc function that would add ‘-E’ after ‘sudo’ if ‘sudo’ and ‘vim’ were detected, but I wasn’t able to get it working; here is my attempt:
vim() {
if [[ $1 == "sudo" && $2 == "vim" ]]; then
command sudo -E vim "$@"
else
command vim "$@"
fi
}