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
/usr/bin/vim

$ echo $EDITOR 
/usr/bin/vim

$ echo $SUDO_EDITOR 
/usr/bin/vim

$ 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
up vote 21 down vote accepted

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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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