I'm trying to have second color highlight in Vim,
The simply way to do is use the :match, :2match, or :3match commands:
:match TODO /pattern/
TODO is the highlight group; pattern will be highlighted like ':/'.
I have hard time to figure out how to remove the color.
You can undo a :match TODO /pattern/ command with :match none, or just :match. Same for the other :2match and :3match variants.
The generic matchdelete() function typically is used in scripts to undo a match added via :matchadd(). As you use these commands interactively (for a limited set of matches), I would not advise that you switch to them.
There isn't a command for this as far as I know, but you can use the clearmatches() and matchdelete() functions.
clearmatches() will remove all matches:
:call clearmatches()
And matchdelete() to remove a specific match instance; you can get the ID from getmatches():
:for m in filter(getmatches(), { i, v -> l:v.group is? 'TODO' })
: call matchdelete(m.id)
:endfor
You can also filter matches on e.g. the matching pattern with the pattern key. An :Unmatch command might look like:
command! -nargs=1 Unmatch
\ for m in filter(getmatches(), { i, v -> l:v.group is? <q-args> })
\| call matchdelete(m.id)
\| endfor
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With