如何使用 update-alternatives 配置 neovim 以实现 ex view 和 vimdiff 行为?

发布于 2025-01-18 23:40:39 字数 639 浏览 1 评论 0原文

当然,我们可以创建别名,但随后我们将Debian集成放松。例如,这3个第一个作品,因为它们只是别名,但最后3个失败是:

NVIM_PATH=/usr/local/bin/nvim
update-alternatives --install /usr/bin/vi vi "${NVIM_PATH}" 110
update-alternatives --install /usr/bin/vim vim "${NVIM_PATH}" 110
update-alternatives --install /usr/bin/editor neovim /usr/local/bin/nvim 110
update-alternatives --install /usr/bin/view view "${NVIM_PATH}" 110
update-alternatives --install /usr/bin/vimdiff vimdiff "${NVIM_PATH}" 110
update-alternatives --install /usr/bin/ex ex "${NVIM_PATH}" 110

视图,Vimdiff和Ex命令正常启动NVIM,而不是分别仅阅读,diff和ex模式。

为什么NVIM反应与VIM不同? 我们应该如何将Debian/Ubuntu中的更新范围集成?

Of course, we could create aliases, but then we loose the Debian integration. For instance, the 3 first works, as they are just aliases, but the 3 last fails:

NVIM_PATH=/usr/local/bin/nvim
update-alternatives --install /usr/bin/vi vi "${NVIM_PATH}" 110
update-alternatives --install /usr/bin/vim vim "${NVIM_PATH}" 110
update-alternatives --install /usr/bin/editor neovim /usr/local/bin/nvim 110
update-alternatives --install /usr/bin/view view "${NVIM_PATH}" 110
update-alternatives --install /usr/bin/vimdiff vimdiff "${NVIM_PATH}" 110
update-alternatives --install /usr/bin/ex ex "${NVIM_PATH}" 110

The view, vimdiff and ex commands just starts nvim normally, instead of respectively read-only, diff, and ex mode.

Why is nvim reacting differently than vim ?
How should we do to keep the update-alternatives integration in Debian/Ubuntu ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

总以为 2025-01-25 23:40:39
update-alternatives --install /usr/bin/editor editor /usr/bin/vi 10
update-alternatives --install /usr/bin/editor editor /usr/bin/vim 20
update-alternatives --install /usr/bin/editor editor /usr/local/bin/nvim 30
update-alternatives --install /usr/bin/editor editor /usr/bin/view 40
update-alternatives --install /usr/bin/editor editor /usr/bin/vimdiff 50
update-alternatives --install /usr/bin/editor editor /usr/bin/ex 60

为首选编辑器设置高优先级。

update-alternatives --install /usr/bin/editor editor /usr/bin/vi 10
update-alternatives --install /usr/bin/editor editor /usr/bin/vim 20
update-alternatives --install /usr/bin/editor editor /usr/local/bin/nvim 30
update-alternatives --install /usr/bin/editor editor /usr/bin/view 40
update-alternatives --install /usr/bin/editor editor /usr/bin/vimdiff 50
update-alternatives --install /usr/bin/editor editor /usr/bin/ex 60

Set the High priority for the preferred editor.

云醉月微眠 2025-01-25 23:40:39

/usr/bin/中制作助手脚本以提供所需的功能。

sudo nvim/usr/bin/nview

#!/bin/bash

exec nvim -R "$@"

sudo nvim/usr/bin/nvimdiff

#!/bin/bash

exec nvim -d "$@"

使这些文件可执行并安装脚本:

sudo chmod +x /usr/bin/nview /usr/bin/nvimdiff
sudo update-alternatives --install /usr/bin/view view /usr/bin/nview 100
sudo update-alternatives --install /usr/bin/vimdiff vimdiff /usr/bin/nvimdiff 100

afaik,neovim do不提供任何ex模式。

(这是一个古老的问题,希望它将有助于寻找答案的人)

删除neovim时,您必须手动运行这些内容:

sudo update-alternatives --remove view /usr/bin/nview
sudo update-alternatives --remove vimdiff /usr/bin/nvimdiff
sudo rm /usr/bin/nview /usr/bin/nvimdiff

Make helper scripts in /usr/bin/ to provide the required functionality.

sudo nvim /usr/bin/nview

#!/bin/bash

exec nvim -R "$@"

sudo nvim /usr/bin/nvimdiff

#!/bin/bash

exec nvim -d "$@"

Make these files executable and install the scripts:

sudo chmod +x /usr/bin/nview /usr/bin/nvimdiff
sudo update-alternatives --install /usr/bin/view view /usr/bin/nview 100
sudo update-alternatives --install /usr/bin/vimdiff vimdiff /usr/bin/nvimdiff 100

AFAIK, neovim does not provide any ex mode.

(This is an old question, hopefully, it will help those looking for an answer)

When removing neovim, you have to run these manually:

sudo update-alternatives --remove view /usr/bin/nview
sudo update-alternatives --remove vimdiff /usr/bin/nvimdiff
sudo rm /usr/bin/nview /usr/bin/nvimdiff
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文