I want to highlight an object in Vim C#.
I do the following in cs.vim:
syn match csObject "[A-Z][_a-zA-Z0-9]*\.[A-Z]"
And highlight it in my color theme
hi csObject guifg=#ff0000
However it paints also the . and the first letter from the next "word".

How to highlight only the match before the dot?
EDIT
Thanks to the @romainl answer I found out that \zs sets the start of a match and \za sets the end of a match.
That's allowed me to make the match properly:
syn match csObject "[ \t\(\!]\zs[A-Z][_a-zA-Z0-9]\{-}\ze\.[A-Z]"
Syntax highlighting enables Vim to show parts of the text in another font or color. Those parts can be specific keywords or text matching a pattern. Vim doesn't parse the whole file (to keep it fast), so the highlighting has its limitations.
To automatically highlight the current word, type z/ .
You only need one tiny modification to your regular expression to solve your issue.
Your pattern actually covers Application, the ., and the following uppercase letter. What you should do is use \ze to mark the end of the "useful" part of your pattern:
syn match csObject "[A-Z][_a-zA-Z0-9]*\ze\.[A-Z]"
Also, I would use \{-} instead of the too greedy *.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With