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

mer*_*011 1 vim syntax-highlighting vim-syntax-highlighting

假设我想在C被调用中定义一个新关键字Foo.我在系统上没有root,所以我无法修改文件/usr/share/vim/vim74/syntax/c.vim.

我尝试在我的底部添加以下内容.vimrc,但它根本没有效果.特别是,当我编辑一个名为Main.c和写的文件时Foo,该单词不会突出显示方式int.

syn keyword cType Foo
Run Code Online (Sandbox Code Playgroud)

增强现有语法突出显示规则的正确方法是什么vim

R S*_*ahu 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