Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 509
Aron Lee Avatar asked Dec 23 '22 04:12

Aron Lee


2 Answers

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.

like image 113
Ingo Karkat Avatar answered Dec 29 '22 00:12

Ingo Karkat


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
like image 43
Martin Tournoij Avatar answered Dec 28 '22 23:12

Martin Tournoij