BiBi BiBi - 7 months ago 90
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

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?


You need to use the lookaround:

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


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