假设我想在名为C
的{{1}}中定义一个新关键字。我在系统上没有root,因此我无法修改文件Foo
。
我尝试在/usr/share/vim/vim74/syntax/c.vim
的底部添加以下内容,但它根本没有效果。
特别是,当我编辑名为.vimrc
的文件并编写Main.c
时,该字词不会以Foo
的方式突出显示。
int
在syn keyword cType Foo
?
答案 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