The Computer Oracle

Setting up multiple highlight rules in vim

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: The World Wide Mind

--

Chapters
00:00 Setting Up Multiple Highlight Rules In Vim
00:25 Accepted Answer Score 10
00:57 Answer 2 Score 8
01:16 Answer 3 Score 1
01:35 Thank you

--

Full question
https://superuser.com/questions/211916/s...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#vim #highlighting

#avk47



ACCEPTED ANSWER

Score 10


One way:

highlight EWOL ctermbg=lightgray ctermfg=black guibg=lightgray guifg=black
match EWOL /\%>20v.\+\|\s\+$/

Another:

highlight ExtraWhitespace ctermbg=lightgray ctermfg=black guibg=lightgray guifg=black
match ExtraWhitespace /\s\+$/

highlight OverLength ctermbg=lightgray ctermfg=black guibg=lightgray guifg=black
2match OverLength /\%>80v.\+/

Also available: 3match. Up to three matches can be active at a time. Or you can use matchadd() to create matches without limit to the quantity.

Note: 3match is used by matchparen, so will conflict if you use it.




ANSWER 2

Score 8


Use matchadd(), so add this to your .vimrc:

highlight ExtraWhitespace ctermbg=grey guibg=grey
call matchadd('ExtraWhitespace', '\s\+$', 11)

highlight OverLength ctermbg=lightgrey guibg=lightgrey
call matchadd('OverLength', '\%>80v.\+')

To view all matches:

:echo getmatches()

To remove matches use matchdelete().




ANSWER 3

Score 1


What about using this

:sy[ntax] match {group-name} [{options}] [excludenl] {pattern} [{options}]

:highlight ExtraWhitespace ctermbg=lightgray guibg=lightgray
:syntax match ExtraWhitespace /\s\+$/
:highlight OverLength ctermbg=lightgray guibg=lightgray
:syntax match OverLength /\%>80v.\+/

You can match many number of patterns using this ...