title: How can I highlight member variables in Python?
body: <p>I'm trying to set up a certain type of syntax highlighting for Python.</p>
  
  <p>I want <code>self</code> and <code>cls</code> to be highlighted like comments.
  I want member variables to be highlighted like functions.</p>
  
  <p>For example, if <code>normal text</code> is (white), <code>comments</code> are (gray), and <code>functions</code> are (red):</p>
  
  <pre><code>self._member
  </code></pre>
  
  <p>should be <code>self</code>(gray)<code>.</code>(white)<code>_member</code>(red)</p>
  
  <pre><code>self._member.other.method()
  </code></pre>
  
  <p>should be <code>self</code>(gray)<code>.</code>(white)<code>_member</code>(red)<code>.other.method()</code>(white)</p>
  
  <pre><code>self._method()
  </code></pre>
  
  <p>should be <code>self</code>(gray)<code>._method()</code>(white)</p>
  
  <p>I tried copying and modifying the syntax for decorators since they seemed similar, but no luck. I also took a <a href="http://vimdoc.sourceforge.net/htmldoc/syntax.html" rel="nofollow">look at the docs</a>, but they were pretty intense. Any idea on how I could do this?</p>
  
  <p>Edit:</p>
  
  <p>I <em>almost</em> got it:</p>
  
  <pre><code>syn keyword pythonThis   cls self
  syn match   pythonMember "\(cls\.\|self\.\)\@&lt;=[A-Za-z_]\+\(\.\| \)"
  
  hi link pythonThis    Comment
  hi link pythonMember  Function
  </code></pre>
  
  <p>The only problem with this is that a dot following a member variable is red instead of white (<code>self._member.other.method()</code> isn't highlighted <em>exactly</em> as specified above). Not a big deal, but it would be nice to know how to ignore multiple groups in a single match (It doesn't seem that you can use <code>\@&lt;=</code> multiple times).</p>