Using `alternatives`2021-06-21 #linux #cli #vim #alternatives
alternatives allows one to select a different executable for a normal command
line program, but how does it work?
I'll give an example: I enjoy using NeoVim instead of Vim for different
reasons. But there is a nag that I keep hitting: NeoVim executable is called
nvim instead of the
vim for... Vim.
I could change two different environment variables,
nvim, so any application that wants to open an external editor would call
NeoVim instead. But, unfortunately, my muscle memory doesn't work with
environment variables, so either I keep correcting myself to type
vim or I find a way to, when I call
vim, it should actually call
The initial solution is to use aliases, so
alias vim nvim (in Fish) would
vim actually run
nvim... except when I use
sudo, which doesn't
expand the alias before its call. The actual solution would be something
global, that takes care of this.
And that's what
In my case, what I actually need to do is run the follow command:
sudo alternatives --install /usr/bin/nvim vim /usr/bin/vim 1
What does it do:
- Say I want to use
- ... which I'll call "vim" (which is the name
alternativesuses in its configuration)
- ... making a symlink into
- ... with priority 1.