I’m a terminal junkie, and a heavy user of Neovim. This leads to a couple of issues when I’m using sudo:
- I’ve got
vimin my aliases file (which I source from both .bashrc and .zshrc, so I have consistency). Sudo doesn’t respect aliases by default, so opens up vanilla Vim
- When I
sudo nvimit brings up Neovim, but just uses the boring default settings (since I don’t have anything set up for the root user)
What I Want
What I want: I type
sudo vim and it opens up Neovim with my user settings
I’ve finally worked out a fix. In your .zshrc (or .bashrc or .whateverrc) file:
alias sudo='nocorrect sudo -E '
Now, when I type
sudo vim foo.txt, it brings up Neovim with my own settings!
Breaking It Down
nocorrect- required by zsh for autocorrect to work with sudo
-E- tells sudo to respect the environment it’s being started in (i.e. the environment with my dotfiles)
- The space at the end - passes aliases through to sudo