Vim conflict syntax (when using a keyword)

I am brand new to Vim and have the following problem:

In my .gvimrc I defined

 syn keyword Todo PMID 

highlight all PMID in the files that I am editing. This works well enough until the general syntax highlighting is added to the file (via setf or autocmd BufRead,BufNewFile … )

My question is: how do I save a list of individual keywords that are highlighted no matter which file I edit and what syntax is highlighted for this file?

+4
source share
3 answers

In this case, the matches fit:

 let s:kwreg='\v<%(PMID|OTHER|OTHER2)>' let s:kwsyn='Todo' augroup MyKeywords autocmd! autocmd WinEnter * if !exists('w:my_keyword_mnr') | \ let w:my_keyword_mnr=matchadd(s:kwsyn, s:kwreg) | \ endif augroup END let s:curtab=tabpagenr() for s:tab in range(1, tabpagenr('$')) execute 'tabnext' s:tab let s:curwin=winnr() for s:win in range(1, winnr('$')) execute s:win.'wincmd w' let w:my_keyword_mnr=matchadd(s:kwsyn, s:kwreg) endfor execute s:curwin.'wincmd w' endfor execute 'tabnext' s:curtab unlet s:curtab s:curwin s:tab s:win 
+4
source

If you want it to be highlighted everywhere (as a kind of “overlay”), use matchadd() , as shown by ZyX's answer.

If this is a syntax extension for one / several file types (for example, only Java and Python files), put the definition :syntax in ~/.vim/after/syntax/<filetype>.vim . You need to study the source syntax a bit and perhaps add the containedin=<groupNames> so that your objects integrate correctly.

+2
source

You can use something like this:

 syntax match pmidTODO /TODO\|PMID/ hi link pmidTODO Todo hi Todo guibg=yellow guifg=black 

This should work even when Todo overridden by Vim syntax files.

Edit: As ZyX noted, this did not save the syntax changes.

+1
source

Source: https://habr.com/ru/post/1436980/


All Articles