Aron Lee
Aron Lee

Reputation: 617

How to remove color highlight from match() function from Vim

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.

Upvotes: 5

Views: 903

Answers (2)

Ingo Karkat
Ingo Karkat

Reputation: 172540

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.

Upvotes: 6

Martin Tournoij
Martin Tournoij

Reputation: 27822

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

Upvotes: 5

Related Questions