5

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.

2 Answers 2

1

timtowtdi

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.

symlink

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.

# HOME=/home/chicks

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.

0
6

When you run vim using su or 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

1
  • That works, too. Glad I could help.
    – Pak
    Aug 25, 2017 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.