Vim highlight a list of words

后端 未结 3 632
逝去的感伤
逝去的感伤 2020-12-28 16:41

I need to highlight a list of words in vim, preferably the words should be defined in a file. A bit like spell checking. I have been looking at http://vim.wikia.com/wiki/Hig

3条回答
  •  执笔经年
    2020-12-28 17:20

    I would recommend you use syn keyword for this. There are other options like :match as suggested by michael.kebe and syn match etc, but these are all based on regular expression matches. The disadvantage of this is that as the number of words that you want to match increases, the speed of Vim decreases. Keyword matches are much faster. You can also easily define multiple keywords on a line (although there is a limit of about 512 characters on a line, if memory serves me correctly).

    syn keyword Todo word1 word2 word3
    syn keyword Todo word4
    syn keyword Todo word5
    

    Put these lines in any file and :source it or dump it in your ~/.vim/after/syntax/c.vim for it to be sourced automatically for all C files (pick your syntax file for the file type you're interested in).

    As with michael.kebe's answer, the first parameter (Todo in this case) is the highlight group. You can make up your own group if you want to and define the highlighting:

    syn keyword MyHighlightGroup word6 word7
    " Then EITHER (define your own colour scheme):
    hi MyGroupName guifg=Blue ctermfg=Blue term=bold
    " OR (make the colour scheme match an existing one):
    hi link MyGroupName Todo
    

提交回复
热议问题