When doing sudo visudo
, the default editor is nano
.
I want to change it to vi
or vim
.
I already made vim
the default editor, and use it as a substitute for gedit
to open php, .txt, .c and .h files, by placing a vim.desktop
file in ~/.local/share/applications/
and by correctly editing either ~/.local/share/applications/mimeapps.list
or /etc/gnome/defaults.list
. However apparently this does not apply to nano
.
Any clue ?
Best Answer
The problem is not that it does not apply to
nano
, it's that it does not apply to the shell:Just set the
VISUAL
environment variable:Add this too ~/.bashrc to make it permanent.
As you seem to use vim in general, set both
VISUAL
andEDITOR
:or more POSIX-correct
I assume
nano
was the value of one or both variables.To make use of the editor in visudo actually, we need to handle that
sudo
does not keep the environment variables by normally. The option-E
changes that.Without the
-E
here, you would end up with a default ofnano
againThe two variables where in use long before files named
*.desktop
ormime*
even existed.(And the impressive thing is: they were actually used as a common standard.)
In Ubuntu, the system default seems to be set with
sudo update-alternatives --config editor
. It shows a menu to change the current association.See section
ENVIRONMENT
inman visudo
: