Vimrc:如何重用不同文件类型的代码和定义?
我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
: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.