I have the following code in my ini.vim:

augroup HiParens
    autocmd Syntax c :syn match Parens /[(){}]/
    autocmd Syntax c :syn match Bracks /[\[\]]/
augroup End

And highlighting is done in ~/.config/nvim/after/ftplugin/c.vim

hi Parens ctermfg=XXX
hi Bracks ctermfg=XXX

The first match /[(){}]/ works as expected. The second seem to do nothing. Yet this is the way I understand the help page I am supposed to do this. I found somewhere else here on SE a suggestion about doing exactly this escaping but can't find the link anymore. I'm a bit surprised, for I would think such escaping would be pretty logical and I also don't get any Errors when loading a C file. Does anybody know what I did wrong? Must be a stupid detail failure on my end...

  • What happens if you add containedin=ALL to the Bracks statement?
    – Ralf
    Sep 21, 2019 at 8:10
  • Hi Ralf, I'm not sure how to use that. I tried ... match Bracks containedin=ALL /[[]]/ and ... match Bracks /[[]]/ containedin=ALL. Neither works unfortunately.
    – chalybeum
    Sep 21, 2019 at 9:34
  • 1
    /[\[\]]/ actually matches \, [, and ]. The pattern you want is /[[\]]/, i.e. only ] needs to be escaped inside a collection.
    – Mass
    Sep 21, 2019 at 12:03
  • Ok, I can see some rationale in that. Unfortunately it doesn't work also.
    – chalybeum
    Sep 21, 2019 at 12:32

1 Answer 1


It works for me in Vim (8.1.2044).

Anyway, I would recommend to create the file ~/.config/nvim/after/syntax/c.vim to extend the C highlighting.

syn match Parens /[(){}]/
syn match Bracks /[[\]]/

hi Parens term=underline ctermfg=11 guifg=Yellow
hi Bracks term=underline ctermfg=11 guifg=Yellow

Adjust hi ... to your liking.

For working with syntax and highlighting I have the following in my vimrc:

command SynID  echo synIDattr(synID(line("."), col("."), 1), "name")

Move the cursor to the place you want to inspect (e.g. a bracket) and execute :SynID. It will print the name of the syntax item under the cursor. If it prints nothing, your syntax match... does not work. If it prints the correct name, but is not higlighted, there is a problem with the hi ... statement. If it prints a different name, you might want to look at :help :syn-contains, :help :syn-contained and :help :syn-containedin.

  • 1
    Cool, simply using ~/.config/nvim/after/syntax/c.vim did the trick. I don't know why it wouldn't in ini.vim but this is way better for organization anyway. Thanks a lot! Also this inspector thingy is quite handy. Still a long way to go in learning VimL.
    – chalybeum
    Sep 23, 2019 at 12:40

Your Answer

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

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