BiBi BiBi - 1 year ago 185
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?

Answer Source

You need to use the lookaround:

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


:syn match pythonBoolean "\(\W\|^\)\@<=self\(\.\)\@="
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download