0

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

First thing first, the right way to add language specific custom syntax highlighting is to place your syntax file, in our case c.vim, in ~/.vim/after/syntax/. (Thanks Ben)

Then it turns out the answer is to add syn match cType /\((\)\@1<=s_\w\+/

Thanks to Knop on freenode's #vim

Here the relevant part of vim help :

\@123<=
        Like "\@<=" but only look back 123 bytes. This avoids trying lots
        of matches that are known to fail and make executing the pattern very
        slow.  Example, check if there is a "<" just before "span":
                /<\@1<=span
        This will try matching "<" only one byte before "span", which is the
        only place that works anyway.
        After crossing a line boundary, the limit is relative to the end of
        the line.  Thus the characters at the start of the line with the match
        are not counted (this is just to keep it simple).
        The number zero is the same as no limit.
1
  • 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 Mar 7 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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