Definition of colored keywords working with all syntax files

I want to define a list of approx. 20 keywords that will be the same color regardless of the active syntax file. I copied and pasted the following into my .vimrc to highlight the word DONE, but it won't work.

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

      

Is it possible? And if so, what am I missing?

+2


source to share


1 answer


Possibly, but you will need to do so after syntax highlighting is highlighted (most syntax markers start with :syn clear

, which will erase what you did). This can be done using autocmd. Try the following:

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()

      

Note that a portion of the syn area cannot be guaranteed as there are various overlapping area marker problems that may cause problems.

Also, in general, if there are areas where you want the highlighting to appear, they must be explicitly listed, which can make things a little messy: for example,



" Allow this keyword to work in a cComment
syn keyword tododone DONE containedin=cComment

      

For more information see

:help :syn-keyword
:help :syn-region
:help :function
:help :autocmd
:help Syntax
:help :syn-containedin
:help :syn-priority

      

+3


source







All Articles