How do I find out what my default terminal text editor is? [duplicate]
In Ubuntu, there is a generic editor
command which is set by the Debian alternatives system.
If you do:
editor foobar.txt
the file will be opened using the original editor e.g. vim
, nano
which is prioritized as editor
currently.
You can check the details with:
update-alternatives --display editor
To set a new editor as editor
:
sudo update-alternatives --config editor
Also note that bash
checks some environment variables for tasks related to it, to be exact bash
checks VISUAL
, EDITOR
one after another. If unset, bash
defaults to nano
(unless an editor you've installed has overridden this).
Some processes spawned from bash
check these environment variables too.
The default editor is as defined by the EDITOR
, or VISUAL
, environment variable(s).
The default editor is vi
if neither were defined. Add
export EDITOR="/bin/nano"
to your ~/.bashrc
file to set, for example, nano
as your default editor.
To see if the environment variable is set, you can use
printenv | grep EDITOR
or
set | grep EDITOR
One can dereference the value of the named environment variable by prefixing it with a "$"
$ echo $EDITOR
or
$ echo $VISUAL
There is actually git var -l
which allows you to list the variables, including GIT_EDITOR
variable. Here's mine (private info is unset of course):
$ git var -l
user.name=*****
user.email=****
GIT_COMMITTER_IDENT=****
GIT_AUTHOR_IDENT=****
GIT_EDITOR=editor
GIT_PAGER=pager
As heemayl already pointed out, editor
command is the one set by /etc/alternatives/editor
. In my case, that's nano
(which I assume is default for Ubuntu, because I don't remember consciously making an effort to change my default editor).
But on other systems other than Ubuntu (or I should say which have no Debian's alternatives system) , there is no editor
. Let's, however read up the man git
:
GIT_EDITOR
This environment variable overrides $EDITOR and $VISUAL. It is used by several Git commands when, on interactive mode, an editor is to be launched. See also git-var(1) and the core.editor option in git- config(1).
And if we look through git-var
it tells us
The order of preference is the $GIT_EDITOR environment variable, then core.editor configuration, then $VISUAL, then $EDITOR, and then the default chosen at compile time, which is usually vi.
Thus it is a mere perculiarity of Ubuntu that it has Debian's alternatives system. On other systems which don't have Debian's alternatives systems it would default to vi