So I have to follow a name convention for my C data types :

Typedefs must start with a t_ prefix such a t_mytype.

Structs must start with a with an s_ prefix and so on for other data types.

So I added syn match cType /\(\s\|^\|(\)s_\w\+/ to my /usr/share/vim/vim81/syntax/c.vim file and it is working almost as intended except that when in front of a parenthesis, the parenthesis is also highlighted.

This is minor annoyance but I would very much like to know what I am doing wrong. What can I do to exclude that paenthesis from higlighting ?

Thanks in advance dear vimmers.

1 Answer 1


You can write language specific highlighting commands in a your_favorite_language.vim file in ~/.vim/after/syntax. In your case c.vim.

The reason for putting it there is that it will remain there across vim/distro updates.

For C, the command goes like this :

syn match cType /some_vim_regex_pattern/

The vim regex pattern for a word is \<word\>. That's a convenient abstraction because you don't have to care if you word has start of the line (\^), whitespace (\s), parentheses or any other non-word delimiter before/after it.

So in your case, you want :

syn match cType /\<t_\w\+\>/

If you want to know wore about vim's regular expressions here is a useful link : http://www.vimregex.com/

  • 2
    PS you should probably use ~/.vim/after/syntax/c.vim; if you update the distribution files, your change will get blown away.
    – D. Ben Knoble
    Commented Mar 7, 2021 at 20:42

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.