I have a very strange issue. I am running vim on my Centos 7 box and having issues getting it to load my .vimrc when I run sudoedit or ssh -e vim.

When I run sudoedit I end up with a few of my settings carrying over but none of my custom colors or any of my key mappings transfer over.

I do see line numbers and I think my indentation settings are working, but not much else.

Here you can see what it looks like normally:

Called as vim

Here is what it looks like when using sudoedit:

Called with sudoedit

I included my :version output just to show it's not calling vi or some other version of the editor, and it clearly shows that both are calling the same .vimrc file. It's just that one is actually reading it and the other isn't...

  • 2
    One output says the system vimrc file is /etc/virc and the other says its /etc/vimrc. What happens if you run EDITOR=vim sudoedit?
    – muru
    Oct 20 '16 at 6:04
  • Declaring the EDITOR variable before running sudoedit seems to work. However I'm not sure why it doesn't read the environment variable that I declared in my .bashrc
    – KroniK907
    Oct 22 '16 at 3:42
  • Did you ever figure this out? Setting EDITOR in the same line as sudoedit works for me too, but I don't understand why??
    – Dan
    Sep 12 '17 at 0:14

When calling sudoedit or sudo -e, sudo will start the editor defined by the environment variables SUDO_EDITOR, VISUAL and EDITOR (in that order) or will typically fall back to vi.

In your screenshots, you can see that two different versions of Vim are called. vim calls a "Huge version without gui", while sudoedit calls a "Small version without gui". Most likely the "Small version..." is called when you invoke vi. The small version does not include syntax highlighting. See :help +feature-list.

By setting EDITOR=vim you tell sudo, that it should start vim. Hence you get the full feature set.

Whether vi and vim starts different executables is installation dependent. On my machine they both start the same version of Vim.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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