I have a custom key mapping
jj to escape, it works for normal file edit but when I open the file as a superuser the key mapping doesn't work anymore, why?
I use Antergos os.
As pointed out in the comments to the other answer you could also solve this with editing root's
~/.vimrc file. There are other options though.
If your personal
~/.vimrc doesn't have any plugin weirdness or hard-coded directories you could just symlink root's
~/.vimrc to your personal one. That way any other settings or future changes would also be available when you are root.
# cd /root # ln -s ~chicks/.vimrc .
HOME environment variable
While testing that I also noticed that if my
HOME environment variable was set to my personal home directory vim picked up the settings from there. My guess is this would work around the directory and plugin weirdness that I worried about with the symlink.
I don't have to do this in normal practice because
sudo bash preserves my home directory and I also get my shell settings too.
When you run vim using
sudo, I believe it's running the root user's
.vimrc (if there is one) instead of yours.
I think the most "correct" way to resolve this is to use
sudoedit rather than running vim directly as the super user. This answer should get you going with that: https://unix.stackexchange.com/questions/46699/start-vim-as-my-user-with-root-privileges