BiBi BiBi - 4 months ago 58
Python Question

Vim Syntax Highlighting: highlight `self` python keyword with regex

I am trying to customize the syntax highlighting for python in vim. I want to highlight the keyword

self
but only when it is followed by a
.
. Here is the code I came up with:

syn match pythonBoolean "\(\Wself\)\%(\.\)"


Unfortunately, the
.
is also highlighted though I use a non capturing group
\%(\.\)
.

Any idea?

Answer

You need to use the lookaround:

:syn match pythonBoolean "\(\W\|^\)\zsself\ze\." 

or

:syn match pythonBoolean "\(\W\|^\)\@<=self\(\.\)\@="
Comments