Fedora 14 uses vi by default when one runs visudo. Is there a way to change this to something else?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
Method 2
The following
- works for distros that use
alternatives(originally just Debian and its forks, but now most major distros, IIUC). -
has the advantage that
- you won’t need to edit
sudoersfirst with its default editor - it works even if package=
sudohas not been built with--with-env-editor
- you won’t need to edit
From a commandline:
- Run
sudo update-alternatives --config editor - Choose desired editor from the (text-mode) menu. If you don’t see the editor you want, you probably need to install it; cancel, do that, and repeat.
sudo visudo should now open the editor of your choice.
Method 3
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).
Method 4
visudo uses the EDITOR variable, for example.
sudo EDITOR=/path/to/editor visudo
Method 5
These steps let me set the editor to vi for visudo on Ubuntu 12.04, they may work for other 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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0