2

I've written a C code syntax rule to highlight function names in function definitions as such:

enter image description here

This is the syntax rule written in ~/.vim/syntax/c.vim:

syntax match cCustomFunc /\w\+\s\+\zs\w\+(/he=e-1
highlight default link cCustomFunc Function

However, when the type in the function definition is a C keyword, the syntax highlighting fails. For example:

enter image description here

Any keyword type such as char, int, void, etc. causes it to fail.

I've tried putting "contains=Type" at the end of the syntax match rule, but it did not work.

How can I make my syntax highlighting rule work when the type in the function definition is a keyword?

1 Answer 1

0

The problem is that the keyword is preventing your regex from matching, since the regex you're using needs to match the whole line, even though you're using \zs to start the capture only at the function name, after the keyword...

You can solve that by using a look-behind regex with \@<=, rather than \zs.

This seems to work ok:

syntax match cCustomFunc /\(\w\+\s\+\)\@<=\w\+(/he=e-1
1
  • 1
    That works. Thanks.
    – user23182
    Commented Jul 27, 2019 at 15:55

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.