How can I designate the editor for visudo?

2.3k Views Asked by At

I executed these two commands:

export VISUAL=/usr/bin/vim
export EDITOR=/usr/bin/vim

And I checked if they were correctly updated by env. But I get a strange editor when I run sudo visudo.

Though I do not know the editor, at the bottom of the console it says this:

-----Mg: sudoers.tmp                  (fundamental)----Top------------------
(Read 29 lines)

This editor is useless because I cannot move the cursor. What I can do is to close the console.

What makes this weird editor run? What command should I execute to change editors?

2

There are 2 best solutions below

3
On BEST ANSWER

From :man visudo (second paragraph):

There is a hard-coded list of one or more editors that visudo will use set at compile-time that may be overridden via the editor sudoers Default variable. This list defaults to /usr/local/bin/vi. Normally, visudo does not honor the VISUAL or EDITOR environment variables unless they contain an editor in the aforementioned editors list. However, if visudo is configured with the --with-env-editor option or the env_editor Default variable is set in sudoers, visudo will use any the editor defines by VISUAL or EDITOR. Note that this can be a security hole since it allows the user to execute any program they wish simply by setting VISUAL or EDITOR.

So, to configure another editor, you need to change the /etc/sudoers configuration and add for example a Defaults editor /usr/bin/vim line.

The strange this is that Vim should be the default editor already?! Based on your output, that may be from Vim (with corrupted terminal), or another editor (you could check the process tree).

1
On

It's an emacs-like editor called mg and you can/should read its man page, $ man mg, to know how it works.

As for how and why it became your default editor… you should take a look at your init files.