简体   繁体   中英

How do I add nvim to update-alternatives when using snap under Ubuntu

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

In order to use it like that you have to 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}"

I'm not sure why using /snap/bin/nvim does not work, even when called from inside the script. At least the workaround works OK.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM