Vimrc:如何重用不同文件类型的代码和定义?

发布于 2024-09-01 08:32:55 字数 632 浏览 2 评论 0原文

我使用 vim 定义了自己的文件类型。例如我有:

.classNotes
.reportJotNotes
.homework

这些文件类型是在 .vim 文件中定义的:

~/.vim/syntax/homework.vim
~/.vim/syntax/reportJotNotes.vim
~/.vim/syntax/homework.vim

其中许多东西都有一些相同的代码。即,它们都具有这样的标题:

syn region JakeTitle start=+=== + end=+===+ oneline
highlight JakeTitle ctermbg=black ctermfg=Yellow

syn region JakeMasterTitle start=+==== + end=+====+ oneline
highlight JakeMasterTitle cterm=bold term=bold ctermbg=black ctermfg=LightBlue

与其将其放在所有三个 .vim 文件中,我宁愿将其放在一个文件中,然后在每个文件中都可以获取它。我该怎么做?

I have defined my own file types using vim. For example I have:

.classNotes
.reportJotNotes
.homework

These file types are defined in .vim files:

~/.vim/syntax/homework.vim
~/.vim/syntax/reportJotNotes.vim
~/.vim/syntax/homework.vim

Many of these things have several of the same code in them. Ie they all have this for titles:

syn region JakeTitle start=+=== + end=+===+ oneline
highlight JakeTitle ctermbg=black ctermfg=Yellow

syn region JakeMasterTitle start=+==== + end=+====+ oneline
highlight JakeMasterTitle cterm=bold term=bold ctermbg=black ctermfg=LightBlue

Instead of having this in all three .vim files I would rather have it in one file and then in each file could source it. How can I do this?

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

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

发布评论

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

评论(1

遇见了你 2024-09-08 08:32:55

您可以使用 :runtime!语法/.vim

使用 :runtime 而不是 :source 的优点是 vim 会在所有正常位置搜索语法文件,因此您不必将所有文件保存在同一个文件夹中,vim 甚至会包含您将来可能创建的任何 /after/syntax/... 文件。

You can use :runtime! syntax/<common>.vim

Using :runtime instead of :source has the advantage that vim will search in all of the normal locations for syntax files so you aren't forced to keep all files in the same folder, and vim will even include any /after/syntax/... files you might create in the future.

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