如何在没有root的情况下为`vim`中的文件类型扩充现有的语法规则集?

时间:2014-05-06 05:20:25

标签: vim syntax-highlighting vim-syntax-highlighting

假设我想在名为C的{​​{1}}中定义一个新关键字。我在系统上没有root,因此我无法修改文件Foo

我尝试在/usr/share/vim/vim74/syntax/c.vim的底部添加以下内容,但它根本没有效果。 特别是,当我编辑名为.vimrc的文件并编写Main.c时,该字词不会以Foo的方式突出显示。

int

syn keyword cType Foo

中增加现有语法突出显示规则的正确方法是什么?

1 个答案:

答案 0 :(得分:7)

以下是有关如何添加到现有语法的VIM文档。

ADDING TO AN EXISTING SYNTAX FILE       *mysyntaxfile-add*

If you are mostly satisfied with an existing syntax file, but would like to
add a few items or change the highlighting, follow these steps:

1. Create your user directory from 'runtimepath', see above.

2. Create a directory in there called "after/syntax".  For Unix:
    mkdir ~/.vim/after
    mkdir ~/.vim/after/syntax

3. Write a Vim script that contains the commands you want to use.  For
   example, to change the colors for the C syntax:
    highlight cComment ctermfg=Green guifg=Green

4. Write that file in the "after/syntax" directory.  Use the name of the
   syntax, with ".vim" added.  For our C syntax:
    :w ~/.vim/after/syntax/c.vim

That's it.  The next time you edit a C file the Comment color will be
different.  You don't even have to restart Vim.

您可以:help mysyntaxfile-add

到达那里