if exists("b:current_syntax") finish endif " Keywords " syn keyword pythonStatement break continue del return pass yield global assert lambda with syn keyword pythonStatement raise nextgroup=pythonExClass skipwhite syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite syn keyword pythonClassVar self cls syn keyword pythonRepeat for while syn keyword pythonConditional if elif else syn keyword pythonException try except finally " The standard pyrex.vim unconditionally removes the pythonInclude group, so " we provide a dummy group here to avoid crashing pyrex.vim. syn keyword pythonInclude import syn keyword pythonImport import syn match pythonRaiseFromStatement '\' syn match pythonImport '^\s*\zsfrom\>' syn keyword pythonStatement print syn keyword pythonStatement exec syn keyword pythonImport as syn match pythonFunction '[a-zA-Z_][a-zA-Z0-9_]*' display contained syn keyword pythonStatement as nonlocal syn match pythonStatement '\v\.@' syn match pythonFunction '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained syn match pythonStatement '\' nextgroup=pythonFunction skipwhite syn match pythonStatement '\' syn match pythonStatement '\' syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonBuiltinObj,pythonBuiltinFunc " " Operators " syn keyword pythonOperator and in is not or syn match pythonOperator '\V=\|-\|+\|*\|@\|/\|%\|&\||\|^\|~\|<\|>\|!=' syn match pythonError '[$?]\|\([-+@%&|^~]\)\1\{1,}\|\([=*/<>]\)\2\{2,}\|\([+@/%&|^~<>]\)\3\@![-+*@/%&|^~<>]\|\*\*[*@/%&|^<>]\|=[*@/%&|^<>]\|-[+*@/%&|^~<]\|[]\+=\{2,}\|!\{2,}=\+' display " " Decorators (new in Python 2.4) " syn match pythonDecorator '^\s*\zs@' display nextgroup=pythonDottedName skipwhite syn match pythonDottedName '[a-zA-Z_][a-zA-Z0-9_]*\%(\.[a-zA-Z_][a-zA-Z0-9_]*\)*' display contained syn match pythonDottedName '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\)*' display contained syn match pythonDot '\.' display containedin=pythonDottedName " " Comments " syn match pythonComment '#.*$' display contains=pythonTodo,@Spell syn match pythonRun '\%^#!.*$' syn match pythonCoding '\%^.*\%(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$' syn keyword pythonTodo TODO FIXME XXX contained " " Errors " syn match pythonError '\<\d\+[^0-9[:space:]]\+\>' display " Mixing spaces and tabs also may be used for pretty formatting multiline " statements syn match pythonIndentError '^\s*\%( \t\|\t \)\s*\S'me=e-1 display " Trailing space errors syn match pythonSpaceError '\s\+$' display " " Strings " " Python 2 strings syn region pythonString start=+[bB]\='+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell syn region pythonString start=+[bB]\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell syn region pythonString start=+[bB]\="""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell syn region pythonString start=+[bB]\='''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell " Python 3 byte strings syn region pythonBytes start=+[bB]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent,@Spell syn region pythonBytes start=+[bB]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent,@Spell syn region pythonBytes start=+[bB]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest,pythonSpaceError,@Spell syn region pythonBytes start=+[bB]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest2,pythonSpaceError,@Spell syn match pythonBytesError '.\+' display contained syn match pythonBytesContent '[\u0000-\u00ff]\+' display contained contains=pythonBytesEscape,pythonBytesEscapeError syn match pythonBytesEscape +\\[abfnrtv'"\\]+ display contained syn match pythonBytesEscape '\\\o\o\=\o\=' display contained syn match pythonBytesEscapeError '\\\o\{,2}[89]' display contained syn match pythonBytesEscape '\\x\x\{2}' display contained syn match pythonBytesEscapeError '\\x\x\=\X' display contained syn match pythonBytesEscape '\\$' syn match pythonUniEscape '\\u\x\{4}' display contained syn match pythonUniEscapeError '\\u\x\{,3}\X' display contained syn match pythonUniEscape '\\U\x\{8}' display contained syn match pythonUniEscapeError '\\U\x\{,7}\X' display contained syn match pythonUniEscape '\\N{[A-Z ]\+}' display contained syn match pythonUniEscapeError '\\N{[^A-Z ]\+}' display contained " Python 2 Unicode strings syn region pythonUniString start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell syn region pythonUniString start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell syn region pythonUniString start=+[uU]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell syn region pythonUniString start=+[uU]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell " Python 3 strings syn region pythonString start=+'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell syn region pythonString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell syn region pythonString start=+'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell syn region pythonString start=+"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell syn region pythonFString start=+[fF]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell syn region pythonFString start=+[fF]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell syn region pythonFString start=+[fF]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell syn region pythonFString start=+[fF]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell " Python 2 Unicode raw strings syn region pythonUniRawString start=+[uU][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell syn region pythonUniRawString start=+[uU][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell syn region pythonUniRawString start=+[uU][rR]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest,pythonSpaceError,@Spell syn region pythonUniRawString start=+[uU][rR]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest2,pythonSpaceError,@Spell syn match pythonUniRawEscape '\%([^\\]\%(\\\\\)*\)\@<=\\u\x\{4}' display contained syn match pythonUniRawEscapeError '\%([^\\]\%(\\\\\)*\)\@<=\\u\x\{,3}\X' display contained " Python 2/3 raw strings syn region pythonRawString start=+[bB]\=[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell syn region pythonRawString start=+[bB]\=[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell syn region pythonRawString start=+[bB]\=[rR]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell syn region pythonRawString start=+[bB]\=[rR]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell syn region pythonRawString start=+[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell syn region pythonRawString start=+[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell syn region pythonRawString start=+[rR]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell syn region pythonRawString start=+[rR]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell syn region pythonRawFString start=+\%([fF][rR]\|[rR][fF]\)'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell syn region pythonRawFString start=+\%([fF][rR]\|[rR][fF]\)"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell syn region pythonRawFString start=+\%([fF][rR]\|[rR][fF]\)'''+ skip=+\\'+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell syn region pythonRawFString start=+\%([fF][rR]\|[rR][fF]\)"""+ skip=+\\"+ end=+"""+ keepend contains=pythonDocTest,pythonSpaceError,@Spell syn region pythonRawBytes start=+\%([bB][rR]\|[rR][bB]\)'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell syn region pythonRawBytes start=+\%([bB][rR]\|[rR][bB]\)"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell syn region pythonRawBytes start=+\%([bB][rR]\|[rR][bB]\)'''+ skip=+\\'+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell syn region pythonRawBytes start=+\%([bB][rR]\|[rR][bB]\)"""+ skip=+\\"+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell syn match pythonRawEscape +\\['"]+ display contained " % operator string formatting syn match pythonStrFormatting '%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString,pythonBytesContent syn match pythonStrFormatting '%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString,pythonBytesContent syn match pythonStrFormatting '%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]' contained containedin=pythonString,pythonRawString,pythonBytesContent syn match pythonStrFormatting '%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]' contained containedin=pythonString,pythonRawString,pythonBytesContent " str.format syntax syn match pythonStrFormat '{{\|}}' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString syn match pythonStrFormat '{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString syn match pythonStrFormat "{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonRawString syn region pythonStrInterpRegion start="{"he=e+1,rs=e+1 end="\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}"hs=s-1,re=s-1 extend contained containedin=pythonFString,pythonRawFString contains=pythonStrInterpRegion,@pythonExpression syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonRawString,pythonFString,pythonRawFString " string.Template format syn match pythonStrTemplate '\$\$' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString syn match pythonStrTemplate '\${[a-zA-Z_][a-zA-Z0-9_]*}' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString syn match pythonStrTemplate '\$[a-zA-Z_][a-zA-Z0-9_]*' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString syn match pythonStrTemplate '\$\$' contained containedin=pythonString,pythonRawString syn match pythonStrTemplate '\${[a-zA-Z_][a-zA-Z0-9_]*}' contained containedin=pythonString,pythonRawString syn match pythonStrTemplate '\$[a-zA-Z_][a-zA-Z0-9_]*' contained containedin=pythonString,pythonRawString " DocTests syn region pythonDocTest start='^\s*>>>' skip=+\\'+ end=+'''+he=s-1 end='^\s*$' contained syn region pythonDocTest2 start='^\s*>>>' skip=+\\"+ end=+"""+he=s-1 end='^\s*$' contained " " Numbers (ints, longs, floats, complex) " syn match pythonHexError '\<0[xX]\x*[g-zG-Z]\+\x*[lL]\=\>' display syn match pythonOctError '\<0[oO]\=\o*\D\+\d*[lL]\=\>' display syn match pythonBinError '\<0[bB][01]*\D\+\d*[lL]\=\>' display syn match pythonHexNumber '\<0[xX]\x\+[lL]\=\>' display syn match pythonOctNumber '\<0[oO]\o\+[lL]\=\>' display syn match pythonBinNumber '\<0[bB][01]\+[lL]\=\>' display syn match pythonNumberError '\<\d\+\D[lL]\=\>' display syn match pythonNumber '\<\d[lL]\=\>' display syn match pythonNumber '\<[0-9]\d\+[lL]\=\>' display syn match pythonNumber '\<\d\+[lLjJ]\>' display syn match pythonOctError '\<0[oO]\=\o*[8-9]\d*[lL]\=\>' display syn match pythonBinError '\<0[bB][01]*[2-9]\d*[lL]\=\>' display syn match pythonFloat '\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>' display syn match pythonFloat '\<\d\+[eE][+-]\=\d\+[jJ]\=\>' display syn match pythonFloat '\<\d\+\.\d*\%([eE][+-]\=\d\+\)\=[jJ]\=' display syn match pythonOctError '\<0[oO]\=\o*\D\+\d*\>' display " pythonHexError comes after pythonOctError so that 0xffffl is pythonHexError syn match pythonHexError '\<0[xX]\x*[g-zG-Z]\x*\>' display syn match pythonBinError '\<0[bB][01]*\D\+\d*\>' display syn match pythonHexNumber '\<0[xX][_0-9a-fA-F]*\x\>' display syn match pythonOctNumber '\<0[oO][_0-7]*\o\>' display syn match pythonBinNumber '\<0[bB][_01]*[01]\>' display syn match pythonNumberError '\<\d[_0-9]*\D\>' display syn match pythonNumberError '\<0[_0-9]\+\>' display syn match pythonNumberError '\<0_x\S*\>' display syn match pythonNumberError '\<0[bBxXoO][_0-9a-fA-F]*_\>' display syn match pythonNumberError '\<\d[_0-9]*_\>' display syn match pythonNumber '\<\d\>' display syn match pythonNumber '\<[1-9][_0-9]*\d\>' display syn match pythonNumber '\<\d[jJ]\>' display syn match pythonNumber '\<[1-9][_0-9]*\d[jJ]\>' display syn match pythonOctError '\<0[oO]\=\o*[8-9]\d*\>' display syn match pythonBinError '\<0[bB][01]*[2-9]\d*\>' display syn match pythonFloat '\.\d\%([_0-9]*\d\)\=\%([eE][+-]\=\d\%([_0-9]*\d\)\=\)\=[jJ]\=\>' display syn match pythonFloat '\<\d\%([_0-9]*\d\)\=[eE][+-]\=\d\%([_0-9]*\d\)\=[jJ]\=\>' display syn match pythonFloat '\<\d\%([_0-9]*\d\)\=\.\d\%([_0-9]*\d\)\=\%([eE][+-]\=\d\%([_0-9]*\d\)\=\)\=[jJ]\=' display " " Builtin objects and types " syn keyword pythonNone None syn keyword pythonBoolean True False syn keyword pythonBuiltinObj Ellipsis NotImplemented syn match pythonBuiltinObj '\v\.@' syn keyword pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__ syn keyword pythonBuiltinObj __loader__ __spec__ __path__ __cached__ " " Builtin functions " syn sync minlines=2000 " This is fast but code inside triple quoted strings screws it up. It " is impossible to fix because the only way to know if you are inside a " triple quoted string is to start from the beginning of the file. syn sync match pythonSync grouphere NONE '):$' syn sync maxlines=200 hi link pythonStatement Statement hi link pythonRaiseFromStatement Statement hi link pythonImport Include hi link pythonFunction Special hi link pythonConditional Conditional hi link pythonRepeat Repeat hi link pythonException Exception hi link pythonOperator Operator hi link pythonDecorator Define hi link pythonDottedName Function hi link pythonDot Normal hi link pythonComment Comment hi link pythonCoding Special hi link pythonRun Special hi link pythonTodo Todo hi link pythonError Error hi link pythonIndentError Error hi link pythonSpaceError Error hi link pythonString String hi link pythonRawString String hi link pythonRawEscape Special hi link pythonUniEscape Special hi link pythonUniEscapeError Error hi link pythonUniString String hi link pythonUniRawString String hi link pythonUniRawEscape Special hi link pythonUniRawEscapeError Error hi link pythonBytes String hi link pythonRawBytes String hi link pythonBytesContent String hi link pythonBytesError Error hi link pythonBytesEscape Special hi link pythonBytesEscapeError Error hi link pythonFString String hi link pythonRawFString String hi link pythonStrInterpRegion Special hi link pythonStrFormatting Special hi link pythonStrFormat Special hi link pythonStrTemplate Special hi link pythonDocTest Special hi link pythonDocTest2 Special hi link pythonNumber Number hi link pythonHexNumber Number hi link pythonOctNumber Number hi link pythonBinNumber Number hi link pythonFloat Float hi link pythonNumberError Error hi link pythonOctError Error hi link pythonHexError Error hi link pythonBinError Error hi link pythonBoolean Boolean hi link pythonNone Constant hi link pythonBuiltinObj Structure hi link pythonBuiltinFunc Function hi link pythonExClass Structure hi link pythonClassVar Identifier let b:current_syntax = 'python'