Issue
I'd like to add nvim (a snap) to update-alternatives
. The problem is that snap seems to work in mysterious ways when determining which program to run:
$ sudo update-alternatives --install /usr/bin/vim vim /snap/bin/nvim 60
$ vim # works
$ vim hello.txt
error: unknown command "hello.txt", see 'snap help'.
If I look at /snap/bin/nvim
it is a link to /usr/bin/snap
:
$ ls -lah /snap/bin/nvim
lrwxrwxrwx 1 root root 13 Jan 25 15:02 /snap/bin/nvim -> /usr/bin/snap
But how does the snap executable determine it needs to run nvim
Solution
You need to set an alias as explained in @Felipe Francisco's answer:
sudo snap alias nvim vim
Source: https://snapcraft.io/docs/commands-and-aliases
As an alternative, you can create a script that starts nvim like this:
#!/usr/bin/env bash
/usr/bin/snap run nvim ${@}
Lets say you call it nvim_start.sh. Now you can use this script in your update-alternatives commands (remember to enable the execution flag):
CUSTOM_NVIM_PATH=/usr/bin/nvim_start.sh
sudo chmod +x "${CUSTOM_NVIM_PATH}"
set -u
sudo update-alternatives --install /usr/bin/ex ex "${CUSTOM_NVIM_PATH}" 110
sudo update-alternatives --install /usr/bin/vi vi "${CUSTOM_NVIM_PATH}" 110
sudo update-alternatives --install /usr/bin/view view "${CUSTOM_NVIM_PATH}" 110
sudo update-alternatives --install /usr/bin/vim vim "${CUSTOM_NVIM_PATH}" 110
sudo update-alternatives --install /usr/bin/vimdiff vimdiff "${CUSTOM_NVIM_PATH}" 110
sudo update-alternatives --set ex "${CUSTOM_NVIM_PATH}"
sudo update-alternatives --set vi "${CUSTOM_NVIM_PATH}"
sudo update-alternatives --set view "${CUSTOM_NVIM_PATH}"
sudo update-alternatives --set vim "${CUSTOM_NVIM_PATH}"
sudo update-alternatives --set vimdiff "${CUSTOM_NVIM_PATH}"
Answered By - Emilio Answer Checked By - Candace Johnson (WPSolving Volunteer)