While reading the git introductory material, I read a piece that brought this question to mind.
How do I use the Terminal to find out what my Default Text Editor is?
Are there a General Commands that I can use to find this out?
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.
emacs
? If I unset VISUAL
and EDITOR
e.g. sudo visudo
runs in nano
for me
git
has to check EDITOR
variable
Dec 14, 2015 at 9:48
emacs
, since emacs
is not installed by default. Installing emacs
probably overrode your previous configuration.
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
$EDITOR
and not EDITOR
. Why? Because one refers to the environment variable by preceding the name with a $ sign. For example $ $EDITOR bla.txt
or echo $EDITOR
or ... So, I am going to reverse the deletion of the $ sign.
Dec 15, 2015 at 16:08
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