Highlight Matching Pair Error

Issue

This is the error I get when I try to insert parentheses or braces:

Error detected while processing function <SNR>36_Highlight_Matching_Pair: line  140: E801: ID already taken: 3

It started occurring after I added the following code to ~/.vim/after/syntax/c.vim

hi WhiteOnMagenta term=standout,bold ctermfg=White ctermbg=Magenta
3match WhiteOnMagenta /TEST/

I think it’s because of a conflict between my match and something in matchparen.vim. The error disappears once I comment out the lines above in my syntax file or if I delete the matchparen plugin file.

I want to keep the matchparen plugin because I like being able to have my parentheses underlined when my cursor is on one of them. I also like using :match instead of syn keyword as shown in Vim highlight a list of words because :match still highlights the keyword even if it’s used in a comment (and syn keyword does not)

Any solution where I can still have underlined parentheses and highlighted keywords (even when used in a comment) will be much appreciated.

Solution

So I’m still not sure what the problem was, but I fixed it by changing all of my match to matchadd like so

Original:

hi WhiteOnMagenta term=standout,bold ctermfg=White ctermbg=Magenta
3match WhiteOnMagenta /TEST/

New (and better):

hi WhiteOnMagenta term=standout,bold ctermfg=White ctermbg=Magenta
let m = matchadd("WhiteOnMagenta", "TEST")

Answered By – J-Win

Answer Checked By – Mildred Charles (AngularFixing Admin)

Leave a Reply

Your email address will not be published.