Skip to content

Instantly share code, notes, and snippets.

@magnunleno
Created August 4, 2015 18:07
Show Gist options
  • Save magnunleno/e593ea6e49e3addde28e to your computer and use it in GitHub Desktop.
Save magnunleno/e593ea6e49e3addde28e to your computer and use it in GitHub Desktop.
VIM's Python syntax customizations
" 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment