The link that you followed was unfortunately generated by ChatGPT, and it demonstrates some of the issues with AI-generated content (and why we ban AI-generated answers here on Ask Ubuntu) see footnote. It's surprising, and a bit disappointing, to see a reputable hosting provider using ChatGPT-generated articles.
The reality is that there are, historically, many ways to choose an editor, and different applications use different methods. ChatGPT came up with a good "guess" (as it often does), but that method only works for some applications, so I'd consider it "wrong" as the answer to an article about, "How to set the default text editor in Linux". The correct answer would be something more like, "It depends on the application".
For instance:
crontab -e
uses select-editor
to allow the user to select their preferred editor the first time it is run. The EDITOR
and VISUAL
environment variables will override this selection, however, if either is present.
Conversely, git
defaults to using vi
, which can be overridden by the presence of an EDITOR
or VISUAL
environment variable, which can in turn also be overridden by the core.editor
Git configuration.
visudo
can use the EDITOR
and VISUAL
variables, but only (if I'm reading man visudo
correctly) if the editor
or env_editor
settings are configured in sudoers
. By default, in the absence of these settings and variables, it defaults to /usr/bin/editor
. Under Ubuntu, with the alternatives
system, /usr/bin/editor
is a symlink to /etc/alternatives/editor
, which in turn is a symlink to your preferred editor (nano
by default).
As mentioned in the other existing answer, this symlink (as with any in the alternatives system) can be updated using the update-alternatives
command.
And these methods for choosing a default editor can even vary from distribution-to-distribution, and some defaults can be compiled into the applications.
Footnote
Certainly, it's easy for a human to make similar mistakes (and I can't promise that mine isn't error-free), but ChatGPT (currently, at least) seems to have a knack for delivering answers that don't quite answer the question that was asked (as in this case), or worse, completely make up settings that don't even exist.
When I try to open the /etc/sudoers file
-- What command did you use to open that?sudo visudo /etc/sudoers