Say I called:

matchadd('my_group', 'regex1')


matchadd('my_group', 'regex2')

I know I could matchdelete() on id, but how could we delete match of my_group?

  • 1
    What do you mean exactly by "delete the match group"?
    – romainl
    Commented Jul 13, 2023 at 13:49
  • 1
    I hope you are not using some generic group name pre-defined by Vim like ErrorMsg. Because in that case you may delete highlightings, that another plugin created and as a user I wouldn't like this Commented Jul 13, 2023 at 16:46
  • Do you still have something open in your question? How can we help you further? If we have answer to your question may be could you accept an answer using the v button next to the arrow voting buttons. It allow the question to rest :-) Commented Jul 17, 2023 at 5:59

1 Answer 1


I would do:

for m in getmatches()
  if m.group == 'my_group'
    call matchdelete(m.id)

  • 1
    It's better to remember the returned ids from matchadd() and use those to clean up. So you don't have to loop over possible many created matches (who knows how many plugins are using that) and this could be potentially a low slower Commented Jul 13, 2023 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.