Appending a new path to VIMRUNTIME variable 将新路径添加到VIMRUNTIME变量

huangapple go评论76阅读模式
英文:

Appending a new path to VIMRUNTIME variable

问题

我已经为特定文件扩展名开发了一个自定义语法高亮器和语法检测器。目前,在我手动复制必要的文件到$HOME/.vim/syntax$HOME/.vim/ftdetect目录时,它可以正常工作。然而,我宁愿不直接修改主目录。

相反,我想将一个新的目录路径附加到VIMRUNTIME变量。这样,当我打开Vim时,它会首先在新目录中搜索语法文件,然后再返回到默认路径。

然而,当我设置了带有额外路径的VIMRUNTIME变量时,Vim无法再定位默认的Vim文件。

是否有解决方案或变通方法,可以让我实现我期望的设置,同时不失去对默认Vim文件的访问权限?

英文:

I have developed a custom syntax highlighter and syntax detector for a specific file extension. Currently, it works fine when I manually copy the necessary files to $HOME/.vim/syntax and $HOME/.vim/ftdetect directories. However, I would prefer not to modify the home directories directly.

Instead, I would like to append a new directory path to the VIMRUNTIME variable. This way, when I open Vim, it would first search for syntax files in the new directory and then fall back to the default path.

However, when I set the VIMRUNTIME variable with the additional path, Vim is no longer able to locate the default Vim files.

Is there a solution or workaround that would allow me to achieve my desired setup without losing access to the default Vim files?

答案1

得分: 1

以下是翻译好的部分:

假设你的插件看起来像这样:

/ foo / bar / ftdetect / xyz.vim
/ foo / bar / syntax / xyz.vim

可以尝试执行以下操作:

$ vim --cmd "set runtimepath^=/foo/bar"

这将在:help 'runtimepath'之前添加/foo/bar

请注意,如果你的插件包含一个after目录,你也需要追加它:

$ vim --cmd "set runtimepath^=/foo/bar" --cmd "set runtimepath+=/foo/bar/after"

但我建议你简单地将你的插件保存在~/.vim目录下。那个目录真的是你自己的,是任何自定义的合适位置。

现在,如果你绝对想将你的vim脚本打包成更大的项目的一部分,那么你需要告诉你的用户在他们的vimrc中添加类似这样的内容:

set runtimepath^=/foo/bar
set runtimepath+=/foo/bar/after

但再次强调,最好将你的支持脚本提交给Vim,以便它们包含在默认发行版中。

英文:

Assuming your plugin looks like this:

/foo/bar/ftdetect/xyz.vim
/foo/bar/syntax/xyz.vim

it is possible to do something like:

$ vim --cmd "set runtimepath^=/foo/bar"

which will prepend /foo/bar to :help 'runtimepath'.

Note that, if your plugin contains an after directory, you will need to append it too:

$ vim --cmd "set runtimepath^=/foo/bar" --cmd "set runtimepath+=/foo/bar/after"

But I would suggest you simply keep your plugin under ~/.vim. That directory is really yours and it is the proper place for any customization.

Now, if you absolutely want to package your vim scripts as part of some larger project, then you will need to instruct your users to add something like this to their vimrc:

set runtimepath^=/foo/bar
set runtimepath+=/foo/bar/after

But again, it seems preferable to submit your support scripts to Vim so that they are included in the default distribution.

huangapple
  • 本文由 发表于 2023年5月25日 02:46:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76326562.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定