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

7,653

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.

Share:
7,653

Related videos on Youtube

the_velour_fog
Author by

the_velour_fog

Updated on September 18, 2022

Comments

  • the_velour_fog
    the_velour_fog almost 2 years

    Ive just installed ubuntu 16.04.2 32 bit on a digital ocean server.

    Digital ocean has tweaked the ubuntu install a bit, for example they have installed full vim as part of the block image they use in their VPS's. I now want to use this - pre-installed - vim as my default editor. so I run

    sudo update-alternatives --config editor
    

    which gives this menu

    $ sudo update-alternatives --config editor
    There are 4 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/vim.basic   30        manual mode
      4            /usr/bin/vim.tiny    10        manual mode
    
    Press <enter> to keep the current choice[*], or type selection number:
    

    note: vim is not there as an option

    Im thinking digital ocean has not added the vim install to the update-alternatives system?
    What is the recommended way to get the /user/bin/vim program added to this menu?
    I guess I could overwrite the /usr/bin/editor symlink that the alternatives system adds or maybe add a symlink in /etc/alternatives pointing to /usr/bin/vim ? but I would like to try the "official" way before I do my "hack" on top of the digital ocean hack.

  • vanadium
    vanadium almost 3 years
    This should be the accepted answer: it answers the question on how to add a custom editor to the alternatives
  • Admin
    Admin about 2 years
    If micro was installed with brew the path would be /home/linuxbrew/.linuxbrew/bin/micro