如何将自定义语法高亮显示在.vimrc中?

时间:2021-11-18 07:33:20

I use a shorthand form for the basic C/C++ types and I want Vim to syntax highlight them. I added

我使用简写形式的基本C / C ++类型,我希望Vim语法突出显示它们。我补充道

syn keyword cType u8 s8 u16 s16 u32 s32 u64 s64 f32 f64 byte

syn关键字cType u8 s8 u16 s16 u32 s32 u64 s64 f32 f64 byte

to my .vimrc, but that doesn't work. What am I doing wrong?

到我的.vimrc,但这不起作用。我究竟做错了什么?

UPDATE 1 It has been suggested elsewhere that the problem is when Vim loads the syntax files for C or C++ it overrides my custom syntax in .vimrc. Is that the problem?

更新1其他地方已经建议问题是当Vim加载C或C ++的语法文件时,它会覆盖.vimrc中的自定义语法。这是问题吗?

UPDATE 2 Duskwuff's answer hinted to me to look at Vim's runtimepath variable, which I am setting to a shared network drive, S:\vim\_vim, but Vim was still looking for the after directory in ~\vimfiles\after, which didn't exist! I added S:\vim\_vim\after to the runtimepath variable and it seems to have fixed the problem of the syntax files not loading.

更新2 Duskwuff的回答暗示我要查看Vim的runtimepath变量,我将其设置为共享网络驱动器,S:\ vim \ _vim,但是Vim仍然在〜\ vimfiles \之后查找after目录,其中没有'存在!我将S:\ vim \ _vim \ after添加到了runtimepath变量中,它似乎修复了语法文件无法加载的问题。

1 个解决方案

#1


6  

If you want to extend the behavior of an existing vim syntax file (e.g, c.vim), create the file $HOME/.vim/after/syntax/c.vim, and add the extra syn command there. It'll be loaded after the main c.vim syntax file.

如果要扩展现有vim语法文件(例如c.vim)的行为,请创建文件$ HOME / .vim / after / syntax / c.vim,并在其中添加额外的syn命令。它将在主c.vim语法文件之后加载。

#1


6  

If you want to extend the behavior of an existing vim syntax file (e.g, c.vim), create the file $HOME/.vim/after/syntax/c.vim, and add the extra syn command there. It'll be loaded after the main c.vim syntax file.

如果要扩展现有vim语法文件(例如c.vim)的行为,请创建文件$ HOME / .vim / after / syntax / c.vim,并在其中添加额外的syn命令。它将在主c.vim语法文件之后加载。