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.

Vicky T
  • 333
  • 1
  • 2
  • 7

2 Answers2

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.

mirk
  • 429
  • 4
  • 4
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.

Tobias Kienzler
  • 720
  • 1
  • 6
  • 22
  • 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 – Tobias Kienzler Mar 12 '13 at 07:47