I'm trying to use sudoedit, but it keeps running the nano editor. My preferred editor is vim. How can I make it the default?

Looking at the man page, man sudoedit, I've noticed the following:

 EDITOR           Default editor to use in -e (sudoedit) mode if neither SUDO_EDITOR nor VISUAL is set.
 SUDO_EDITOR      Default editor to use in -e (sudoedit) mode.
 VISUAL           Default editor to use in -e (sudoedit) mode if SUDO_EDITOR is not set.

So I've set them all to /usr/bin/vim, but sudoedit /etc/hosts still uses nano. Am I missing something?

$ EDITOR=/usr/bin/vim
$ VISUAL=/usr/bin/vim
$ SUDO_EDITOR=/usr/bin/vim

$ echo $VISUAL

$ echo $EDITOR 

$ echo $SUDO_EDITOR 

$ sudoedit /etc/hosts # This is still using nano
  • What about sudo vim? – Cornelius Apr 24 '14 at 17:35
  • @Cornelius That works, that's my workaround for the problem at the moment. – Dan Apr 24 '14 at 17:36
  • 1
    try sudo visudo instead – animaletdesequia Apr 24 '14 at 17:37
  • @darent visudo: /etc/sudoers: Permission denied. What is that? – Cornelius Apr 24 '14 at 17:38
  • 2
    @darent visudo is a different program. It's just there to allow you to edit the sudoers file. man visudo – Dan Apr 24 '14 at 17:38

Run sudo update-alternatives --config editor and choose for vim. After this, sudoedit /etc/hosts should open /etc/hosts using vim.

Alternatively you can use sudo vim /etc/hosts.


Try exporting the variable i.e.:

$ SUDO_EDITOR=/usr/bin/vim
$ export SUDO_EDITOR

A new shell is started when you run the command and if this variable is not exported it will not exist in the new shell.

  • Since the question is more related with exporting vs setting an environment variable and alternative way of doing sudo vim /etc/hosts is not relevant here, this should be the accepted answer. – BcK Aug 5 at 6:58

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.