我想要的是定义一个大约的列表。 20 个关键字,其颜色相同,独立于事件语法文件。 我将以下内容复制并粘贴到我的 .vimrc 中以突出显示“DONE”一词,但它不起作用。
syn match tododone /DONE/
syn region done start=/\*\*DONE/ end=/\*\*/
hi link tododone tDone
hi link done tDone
hi default tDone ctermfg=DarkGreen guifg=White guibg=DarkGreen
这可能吗?如果是的话我错过了什么?
最佳答案
这是可能的,但您必须在定义语法突出显示之后执行此操作(大多数语法突出显示以:synclear
开头,这将删除你已经完成了)。这可以通过 autocmd 来完成。试试这个:
hi link tododone tDone
hi link done tDone
hi default tDone ctermfg=DarkGreen guifg=White guibg=DarkGreen
function! HighlightKeywords()
" syn keyword is faster than syn match and is
" therefore better for simple keywords. It will
" also have higher priority than matches or regions
" and should therefore always be highlighted (although
" see comments about containedin= below).
syn keyword tododone DONE
syn region done start=/\*\*DONE/ end=/\*\*/
endfunction
autocmd Syntax * call HighlightKeywords()
请注意,无法保证同步区域部分,因为区域荧光笔存在各种重叠问题,可能会给您带来问题。
此外,作为一般说明,如果您希望在某些区域中突出显示,则必须明确列出这些区域,这可能会使事情变得有点困惑:例如
" Allow this keyword to work in a cComment
syn keyword tododone DONE containedin=cComment
有关详细信息,请参阅:
:help :syn-keyword
:help :syn-region
:help :function
:help :autocmd
:help Syntax
:help :syn-containedin
:help :syn-priority
关于vim - 定义适用于所有语法文件的彩色关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1524551/