Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Fedora 14 uses vi by default when one runs visudo. Is there a way to change this to something else?

share|improve this question
add comment

3 Answers

up vote 11 down vote accepted

Adding Defaults editor=/path/to/editor in the sudoers file will cause visudo to use the specified editor for changes.

Additionally, if your sudo package has been built with --with-env-editor, as is the default on some Linux distributions, you can also set the EDITOR environment variable by executing export EDITOR=/path/to/editor. Performed on the command line this will revert as soon as that shell session is terminated, setting the variable in a ~/.bashrc or /etc/profile will cause the change to persist.

share|improve this answer
    
Could you please provide the command(s) that you executed? –  Tok Nov 29 '10 at 17:46
    
@Tshepang - You can also set Defaults editor=/usr/bin/nano in the sudoers file to specify an editor. At this point I am assuming that you wish to use nano as specified in your earlier comment. –  Tok Nov 29 '10 at 18:33
    
@Tshepang - Yes, however, this is likely a product of having built the package using --with-env-editor. –  Tok Nov 29 '10 at 18:57
    
@Tok: On what system doesn't visudo honor $VISUAL and $EDITOR? –  Gilles Nov 29 '10 at 20:01
1  
@Gilles - based on my reading Ubuntu has recently changed the build parameters of their sudo package to not include --with-env-editor, recently here meaning within the memory of the internet. Additionally the sudo package changed their default some time ago to use vi as their default editor which I believe coincided with a change to the behavior regarding the acceptance of environmental variables. I do not have a clear timeline of how, when, or if these events relate to each other at this time. –  Tok Nov 29 '10 at 20:33
show 2 more comments

A normal unix program that wants to invoke an editor will run the program whose name is in the EDITOR or VISUAL environment variable, and if the variable is unset, a system-dependent default. Many, but not all, programs check both EDITOR and VISUAL; the distinction is long obsolete (once you would run EDITOR on a teletype and VISUAL on a “glass” terminal…) so you should set both to the same value. There is some disagreement as to whether the contents of the variable should be the full path to an executable, an executable name that's looked up in $PATH, or a shell snippet, so you should stick to a path to an executable not containing any shell metacharacter. The system default when neither variable is set is traditionally vi, though some distributions have changed this to a more newbie-friendly editor such as nano.

visudo checks both VISUAL and EDITOR (this can be compiled out, presumably to dissuade root from using an editor whose security the distribution maker doesn't trust, but even OpenBSD doesn't do this).

share|improve this answer
add comment

These steps let me set the editor to vi for visudo on Ubuntu 12.04, they probably work for most distributions:

Issue command:

sudo visudo

This opens up the sudoers file in nano. Near the top you will see this line:

Defaults    env_reset

Add the following line beneath the above line:

Defaults    editor=/usr/bin/vi

Save the file and exit. Reopen visudo as your default user:

sudo visudo

The sudoers file now opens up in VI.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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