如何在没有root的情况下扩展'vim'中文件类型的现有语法规则集?
假设我想在如何在没有root的情况下扩展'vim'中文件类型的现有语法规则集?,vim,syntax-highlighting,vim-syntax-highlighting,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 在vim中增加现有语法突出显示规则的正确方法是什么?以下是关于如何添加到现有语法的vim文档 ADDING TO AN EXISTING SYNTAX F
C
中定义一个名为Foo
的新关键字。我在系统上没有root,因此无法修改文件/usr/share/vim/vim74/syntax/c.vim
我试图在.vimrc
的底部添加以下内容,但根本没有效果。
特别是,当我编辑一个名为Main.c
的文件并编写Foo
时,该单词不会像int
那样突出显示
syn keyword cType Foo
在
vim
中增加现有语法突出显示规则的正确方法是什么?以下是关于如何添加到现有语法的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.
添加到现有语法文件*mysyntaxfile添加*
如果您对现有的语法文件非常满意,但希望
添加一些项目或更改突出显示,请执行以下步骤:
1.从“runtimepath”创建用户目录,请参见上文。
2.在那里创建一个名为“after/syntax”的目录。对于Unix:
mkdir~/.vim/after
mkdir~/.vim/after/syntax
3.编写一个包含要使用的命令的Vim脚本。对于
例如,要更改C语法的颜色,请执行以下操作:
高亮显示cComment ctermfg=绿色guifg=绿色
4.将该文件写入“after/syntax”目录。使用用户的名称
语法,添加了“.vim”。对于我们的C语法:
:w~/.vim/after/syntax/c.vim
就这样。下次编辑C文件时,注释颜色将为
不一样。您甚至不必重新启动Vim。
您可以通过
:help mysyntaxfile add
来实现这一点。下面是关于如何添加到现有语法的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.
添加到现有语法文件*mysyntaxfile添加*
如果您对现有的语法文件非常满意,但希望
添加一些项目或更改突出显示,请执行以下步骤:
1.从“runtimepath”创建用户目录,请参见上文。
2.在那里创建一个名为“after/syntax”的目录。对于Unix:
mkdir~/.vim/after
mkdir~/.vim/after/syntax
3.编写一个包含要使用的命令的Vim脚本。对于
例如,要更改C语法的颜色,请执行以下操作:
高亮显示cComment ctermfg=绿色guifg=绿色
4.将该文件写入“after/syntax”目录。使用用户的名称
语法,添加了“.vim”。对于我们的C语法:
:w~/.vim/after/syntax/c.vim
就这样。下次编辑C文件时,注释颜色将为
不一样。您甚至不必重新启动Vim。
你可以通过
:帮助mysyntaxfile添加来实现这一目标。你到底是如何知道该函数的名称的?:)当您浏览VIM帮助时,右侧的单词是关键字,您可以通过:help
从命令行获取这些关键字。您还可以使用:vimgrep
命令搜索VIM的帮助。实际上:help help
是一个非常好的起点,它可以帮助您在Vim自己的帮助下快速获得答案。您到底是如何知道该函数的名称的?:)当您浏览VIM帮助时,右侧的单词是关键字,您可以通过:help
从命令行获取这些关键字。您还可以使用:vimgrep
命令搜索VIM的帮助。实际上,:help-help
是一个非常好的起点,它将帮助您在Vim自己的帮助下快速获得答案。