Vim Highlights Word List

I need to highlight a list of words in vim, it is desirable that the words are defined in a file. A bit like spell checking. I looked at http://vim.wikia.com/wiki/Highlight_multiple_words , but this requires that I define each word as a new position and do not support saving words in a file (although they are saved).

+14
vim syntax-highlighting
Nov 12 '10 at 8:05
source share
3 answers

You can use the command :match .

 :match Todo /word1/ 

The first parameter of the command is the highlight group (to view all available groups :highlight ). The second parameter is the search pattern.

You can put them in any file and load it through :source .

Another way is to change the regex (thanks @zpon):

 :match Todo /word1\|word2\|word3/ 

If you want to select them differently:

 :match Todo /word1/ :2match Error /word2/ :3match Title /word3/ 
+31
Nov 12 '10 at 8:16
source share

I would recommend using syn keyword for this. There are other options, such as :match , as suggested by michael.kebe and syn match , etc., but they are all based on regular expressions. The disadvantage of this is that as the number of words you want to combine increases, the Vim speed decreases. Keyword macros are much faster. You can also easily identify multiple keywords per line (although there is a limit of approximately 512 characters in the line if memory is correct for me).

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

Place these lines in any file and :source or upload it to your ~/.vim/after/syntax/c.vim so that it is source d automatically for all C files (select the syntax file for the file type you are interested in).

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

 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 
+12
Nov 12 '10 at 9:17 a.m.
source share

: matching Todo / \ <\ (word1 \ | word2 \ | word3 \) \> /

-one
Mar 30 '16 at 5:27
source share



All Articles