How can I add my desired editor to the "update-alternatives" interactive menu?

Solution 1:

This is not modified, but the standard Ubuntu behaviour up to Zesty. If you do a ls -l on vim (/usr/bin/vim), you see that it is a link to /etc/alternatives/vim, which in turn links to /usr/bin/vim.basic.

Execution of vim --version or vim.basic --version also reveals that they are in fact the same full, "giant" vim version 8.0 without GUI.

To answer your question: Menu choice of vim.basic gives you the desired full vim version. It is just that the name is misleading.

Solution 2:

First set your editor to the right path:

sudo update-alternatives --install /usr/bin/editor editor /usr/local/bin/vim && \
sudo update-alternatives --set editor /usr/local/bin/vim

Then aliases:

sudo update-alternatives --install /usr/bin/vi vi /usr/local/bin/vim 1 && \
sudo update-alternatives --set vi /usr/local/bin/vim

Don't forget the 1 near the end of the first line above.

Solution 3:

You can add any new editor and set it as default by using a single command. In this example you would be adding micro editor, located in /usr/bin/micro as an update alternative editor with a priority of 100. The command is:

sudo update-alternatives --install /usr/bin/editor editor /usr/bin/micro 100

The system will use the editor with the highest priority by default if there isn't any previous selection. So, with this single command, you can add a new editor, and use it as the default editor. All you need is that the priority is larger than any of the previous you have in your update-alternatives list.