VIM 评论中的自定义关键字突出显示

Custom Keyword highlighting within comments for VIM

我想添加应在 vim 中突出显示的自定义关键字。 这些关键字用于标记注释,而不是代码。 这就是我的 .vimrc:

autocmd Syntax * syntax keyword Important containedin=.*Comment contained IMPORTANT

这有效,但只是部分有效,因为关键字 (IMPORTANT) 仅在使用 'C-Style' 注释时突出显示:( /* ... */ ),而不是较短的 ( // ... )符号。 我试过 'containedin=' 标志但没有成功..

这需要为 C/C++ 工作,但显然总体来说会很好!

您需要找出哪个语法组导致突出显示。 :syn list 显示所有活动组,但安装 SyntaxAttr.vim - Show syntax highlighting attributes of character under cursor 插件后更容易。

当我在 C++ 文件的 // comment 行触发它时,它将语法组列为 cCommentL。因此,要解决此问题,您需要扩展正则表达式,要么严格扩展到 containedin=.*CommentL\?,要么扩展到 containedin=.*Comment.*