4
4

3 回答 3

4

In this case matches come handy:

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
于 2012-09-29T20:57:58.997 回答
2

If you want that highlighted everywhere (as a kind of "overlay"), use matchadd(), as shown by ZyX's answer.

If this is a syntax extension for one / a couple of filetypes (e.g. only Java and Python files), put your :syntax definition into ~/.vim/after/syntax/<filetype>.vim. You have to study the original syntax a bit, and possibly add containedin=<groupNames> clauses, so that your items properly integrate.

于 2012-09-30T10:58:05.690 回答
1

You could 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 is redefined by Vim syntax files.

Edit: As ZyX pointed out, this does not survive syntax changes.

于 2012-09-29T21:28:56.737 回答