There is already a generic binary called editor
i.e. /usr/bin/editor
provided by the Debian alternatives system (update-alternatives
).
This binary is actually a symbolic link to /etc/alternatives/editor
:
$ ls -l /usr/bin/editor
lrwxrwxrwx 1 root root 24 Feb 9 2015 /usr/bin/editor -> /etc/alternatives/editor
which in turn is a symbolic link to the actual editor select based on priority or manually :
$ ls -l /etc/alternatives/editor
lrwxrwxrwx 1 root root 18 Feb 10 2015 /etc/alternatives/editor -> /usr/bin/vim.basic
Now if i open a file with :
editor ~/.bashrc
this would actually do :
vim.basic ~/.bashrc
Lets change the editor :
$ sudo update-alternatives --config editor
There are 5 choices for the alternative editor (providing /usr/bin/editor).
Selection Path Priority Status
------------------------------------------------------------
0 /bin/nano 40 auto mode
1 /bin/ed -100 manual mode
2 /bin/nano 40 manual mode
3 /usr/bin/nedit 40 manual mode
* 4 /usr/bin/vim.basic 30 manual mode
5 /usr/bin/vim.tiny 10 manual mode
The one with the *
is the currently selected one, navigate to the one you like and select that by pressing Enter or directly use update-alternatives --set
or you can set priority as you and see in the third column by update-alternatives --install
command. To get information about something you can use update-alternatives --query
or update-alternatives --list
commands.
To install a new alternative use update-alternatives --install
command. For example adding the editor /usr/bin/foobar
to the editor
alternative system and giving it a priority of 100 so that this would be the default now :
sudo update-alternatives --install editor /etc/alternatives/editor /usr/bin/foobar 100
Check man update-alternatives
to get details.