Skip to content

Instantly share code, notes, and snippets.

@magnunleno
Created August 4, 2015 18:07

Revisions

  1. magnunleno created this gist Aug 4, 2015.
    16 changes: 16 additions & 0 deletions python.vim
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    " Match (only 'bar') in function calls like: 'foo.bar()' or 'bar()'
    syn match pythonFunction /\(^\s*\(def\|class\)\s*\w*\)\@<!\w\{1,}\ze(/
    " Match dunder methods/attributes
    syn match pythonBuiltin "__\w*__"
    " Match under methods/attributes
    syn match pythonIdentifier "_\w*_"
    " Match self (not in function declarations)
    syn match pythonFunction /\(^\s*def \s*\w*\s*(\)\@<!self/
    " Match self in function declarations
    syn match pythonIgnore /\(^\s*def \s*\w*\s*(\)\@<=self\ze\s*[,)]/
    " Pseudo-consants in python (Capital letters variables)
    syn match pythonConstant /\<[A-Z_][A-Z_0-9]*\>/

    hi link pythonIgnore Ignore
    hi link pythonIdentifier Identifier
    hi link pythonConstant Constant