vim - 定义适用于所有语法文件的彩色关键字

标签 vim

我想要的是定义一个大约的列表。 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/

相关文章:

linux - Vim 映射复制到系统剪贴板

haskell - 如何使用 vim :split to open ghci and a Haskell file?

vim - vim中有没有办法制作:W to do the same thing as :w?

vim - 使 gvim 将包裹的行视为新行

Ubuntu Vim 全屏并不是真正的全屏

regex - 如何在vim中用大括号括住视觉上选择的文本

vim -- 如何将文件中的行范围读入当前缓冲区

linux - 在 Vim 中重新映射 Escape 键(德语键盘)

Vim:在fortran中跳转到if endif

vim - 我该如何防止vim通过制表符填充.class文件?