22

I would really like it to be vi or vim. I mistakenly typed some vi commands in the default editor for visudo, which I believe is nano, and broke /etc/sudoers so badly I think I am going to have to burn a new image and start over.

I've been able to run visudo again by doing pkexec bash but I broke something in the default line entry and I haven't been able to repair it correctly and sudo won't run.

1
  • 1
    Side note: mcedit is a nice alternative if you don't actually want to remember vim/nano/emacs shortcuts Mar 11 '13 at 12:54
21

You can set the system editor by calling as root:

update-alternatives --set editor /usr/bin/vim.tiny

You have to install vim first.

This will change the editor globally, not just for visudo.

1
  • For a handy TUI to select from a list, run update-alternatives --config editor Aug 16 '19 at 19:17
10

If you want to change this only temporarily, run

EDITOR=vim visudo

as root (else sudo EDITOR=vim visudo). To make vim the default editor for visudo but nothing else, you can put

alias visudo='EDITOR=vim visudo'

into your ~/.alias or ~/.bashrc.

2
  • 1
    EDITOR=vim sudo visudo does not work as expected since sudo by default drops all env variables for security reasons. (I was simply trying out the commands).
    – mirk
    Mar 11 '13 at 20:36
  • 2
    @mirk My bad, sudo belongs in front of the whole line Mar 12 '13 at 7:47

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.