How can I change the default text editor for console programs in Ubuntu. When I run mutt and send a message, it currently loads up Joe and I would prefet to load Vim. I know I can change $EDITOR for me only, but would prefe to do it system wide.
2 Answers
You can change $EDITOR systemwide. Just drop a short script into /etc/profile.d/ which does this. The file only needs a single line:
export EDITOR=/usr/bin/myeditor Edit:
There are two ways (at least :-/) in which a program can find an editor to launch. The traditional Unix/Linux mechanism is to use $EDITOR. In addition to that, Debian (and therefore Ubuntu) has special aliases for various kinds of programs. These are provided by the "alternatives" system (a system of configurable symlinks). For editors this provides the aliases editor and sensible-editor. These can be updated using update-alternatives:
sudo update-alternatives --config editor (same for sensible-editor). This will prompt you for the editor to use.
However, in Debian programs are suppposed to read $EDITOR first:
Thus, every program that launches an editor or pager must use the EDITOR or PAGER environment variable to determine the editor or pager the user wishes to use. If these variables are not set, the programs /usr/bin/editor and /usr/bin/pager should be used, respectively.
These two files are managed through the dpkg "alternatives" mechanism.
[...]
If it is very hard to adapt a program to make use of the EDITOR or PAGER variables, that program may be configured to use /usr/bin/sensible-editor and /usr/bin/sensible-pager as the editor or pager program respectively.
(Debian Policy Manual, http://www.debian.org/doc/debian-policy/ch-customized-programs.html#s11.4 )
In one sentence: Setting $EDITOR globally should be enough.
- Thanks - I had heard of the "alternatives" mechanism but counldnt remember enough to find it. It is really complicated though.justintime– justintime2010-08-10 20:23:32 +00:00Commented Aug 10, 2010 at 20:23
- 2Actually
visudowill not typically work with$EDITORas it is a security concern (at least for ubuntu). The/usr/bin/editoris used.Adam Gent– Adam Gent2016-11-30 17:22:00 +00:00Commented Nov 30, 2016 at 17:22 -
visudonow uses$EDITORin Ubuntu 18.04.Camille Goudeseune– Camille Goudeseune2020-04-02 15:53:44 +00:00Commented Apr 2, 2020 at 15:53
the mechanism in ubuntu (debian) used to solve this problem is described in man update-alternatives. essentially it provides a "pseudo binary" (/usr/bin/editor) which points to the right binary (the "best" alternative)
call
% sudo update-alternatives --config editor to change the current "default". with
% update-alternatives --list editor % update-alternatives --display editor you can see the currently available alternatives.
- This is correct, but editor/sensible-editor is only meant as a fallback mechanism. You can just set $EDITOR. Also, editor/sensible-editor is a Debian convention. Third-party software may not use it, while $EDITOR is a general Unix tradition.sleske– sleske2010-07-28 09:58:38 +00:00Commented Jul 28, 2010 at 9:58
- correct (i am aware of that). it is just a bit tricky to enforce EDITOR to all kind of shells (tcsh, zsh) anyway ... so changing /usr/bin/editor to the wanted default is enough, imho. as a "user" i set my own EDITOR anyway.akira– akira2010-07-28 10:23:15 +00:00Commented Jul 28, 2010 at 10:23