Blame | Last modification | View Log | RSS feed
" Vim syntax file" Language: Python" Maintainer: Dmitry Vasiliev <dima@hlabs.spb.ru>" URL: http://www.hlabs.spb.ru/vim/python.vim" Last Change: $Date: 2006-09-26 15:46:55 +0400 (Втр, 26 Сен 2006) $" Filenames: *.py" Version: 2.5.5" $Rev: 477 $"" Based on python.vim (from Vim 6.1 distribution)" by Neil Schemenauer <nas@python.ca>""" Options:"" For set option do: let OPTION_NAME = 1" For clear option do: let OPTION_NAME = 0"" Option names:"" For highlight builtin functions:" python_highlight_builtins"" For highlight standard exceptions:" python_highlight_exceptions"" For highlight string formatting:" python_highlight_string_formatting"" For highlight indentation errors:" python_highlight_indent_errors"" For highlight trailing spaces:" python_highlight_space_errors"" For highlight doc-tests:" python_highlight_doctests"" If you want all possible Python highlighting:" (This option not override previously set options)" python_highlight_all"" For fast machines:" python_slow_sync"" For version 5.x: Clear all syntax items" For version 6.x: Quit when a syntax file was already loadedif version < 600syntax clearelseif exists("b:current_syntax")finishendifif exists("python_highlight_all") && python_highlight_all != 0" Not override previously set optionsif !exists("python_highlight_builtins")let python_highlight_builtins = 1endifif !exists("python_highlight_exceptions")let python_highlight_exceptions = 1endifif !exists("python_highlight_string_formatting")let python_highlight_string_formatting = 1endifif !exists("python_highlight_indent_errors")let python_highlight_indent_errors = 1endifif !exists("python_highlight_space_errors")let python_highlight_space_errors = 1endifif !exists("python_highlight_doctests")let python_highlight_doctests = 1endifendif" Keywordssyn keyword pythonStatement break continue delsyn keyword pythonStatement exec returnsyn keyword pythonStatement pass print raisesyn keyword pythonStatement global assertsyn keyword pythonStatement lambda yieldsyn keyword pythonStatement withsyn keyword pythonStatement def class nextgroup=pythonFunction skipwhitesyn match pythonFunction "[a-zA-Z_][a-zA-Z0-9_]*" display containedsyn keyword pythonRepeat for whilesyn keyword pythonConditional if elif elsesyn keyword pythonImport import from assyn keyword pythonException try except finallysyn keyword pythonOperator and in is not or" Decorators (new in Python 2.4)syn match pythonDecorator "@" display nextgroup=pythonFunction skipwhite" Commentssyn match pythonComment "#.*$" display contains=pythonTodosyn match pythonRun "\%^#!.*$"syn match pythonCoding "\%^.*\(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$"syn keyword pythonTodo TODO FIXME XXX contained" Errorssyn match pythonError "\<\d\+\D\+\>" displaysyn match pythonError "[$?]" displaysyn match pythonError "[-+&|]\{2,}" displaysyn match pythonError "[=]\{3,}" display" TODO: Mixing spaces and tabs also may be used for pretty formatting multiline" statements. For now I don't know how to work around this.if exists("python_highlight_indent_errors") && python_highlight_indent_errors != 0syn match pythonIndentError "^\s*\( \t\|\t \)\s*\S"me=e-1 displayendif" Trailing space errorsif exists("python_highlight_space_errors") && python_highlight_space_errors != 0syn match pythonSpaceError "\s\+$" displayendif" Stringssyn region pythonString start=+'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonEscape,pythonEscapeErrorsyn region pythonString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonEscape,pythonEscapeErrorsyn region pythonString start=+"""+ end=+"""+ keepend contains=pythonEscape,pythonEscapeError,pythonDocTest2,pythonSpaceErrorsyn region pythonString start=+'''+ end=+'''+ keepend contains=pythonEscape,pythonEscapeError,pythonDocTest,pythonSpaceErrorsyn match pythonEscape +\\[abfnrtv'"\\]+ display containedsyn match pythonEscape "\\\o\o\=\o\=" display containedsyn match pythonEscapeError "\\\o\{,2}[89]" display containedsyn match pythonEscape "\\x\x\{2}" display containedsyn match pythonEscapeError "\\x\x\=\X" display containedsyn match pythonEscape "\\$"" Unicode stringssyn region pythonUniString start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeErrorsyn region pythonUniString start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeErrorsyn region pythonUniString start=+[uU]"""+ end=+"""+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,pythonDocTest2,pythonSpaceErrorsyn region pythonUniString start=+[uU]'''+ end=+'''+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,pythonDocTest,pythonSpaceErrorsyn match pythonUniEscape "\\u\x\{4}" display containedsyn match pythonUniEscapeError "\\u\x\{,3}\X" display containedsyn match pythonUniEscape "\\U\x\{8}" display containedsyn match pythonUniEscapeError "\\U\x\{,7}\X" display containedsyn match pythonUniEscape "\\N{[A-Z ]\+}" display containedsyn match pythonUniEscapeError "\\N{[^A-Z ]\+}" display contained" Raw stringssyn region pythonRawString start=+[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscapesyn region pythonRawString start=+[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscapesyn region pythonRawString start=+[rR]"""+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceErrorsyn region pythonRawString start=+[rR]'''+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceErrorsyn match pythonRawEscape +\\['"]+ display transparent contained" Unicode raw stringssyn region pythonUniRawString start=+[uU][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeErrorsyn region pythonUniRawString start=+[uU][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeErrorsyn region pythonUniRawString start=+[uU][rR]"""+ end=+"""+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest2,pythonSpaceErrorsyn region pythonUniRawString start=+[uU][rR]'''+ end=+'''+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest,pythonSpaceErrorsyn match pythonUniRawEscape "\([^\\]\(\\\\\)*\)\@<=\\u\x\{4}" display containedsyn match pythonUniRawEscapeError "\([^\\]\(\\\\\)*\)\@<=\\u\x\{,3}\X" display containedif exists("python_highlight_string_formatting") && python_highlight_string_formatting != 0" String formattingsyn match pythonStrFormat "%\(([^)]\+)\)\=[-#0 +]*\d*\(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawStringsyn match pythonStrFormat "%[-#0 +]*\(\*\|\d\+\)\=\(\.\(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawStringendifif exists("python_highlight_doctests") && python_highlight_doctests != 0" DocTestssyn region pythonDocTest start="^\s*>>>" end=+'''+he=s-1 end="^\s*$" containedsyn region pythonDocTest2 start="^\s*>>>" end=+"""+he=s-1 end="^\s*$" containedendif" Numbers (ints, longs, floats, complex)syn match pythonHexNumber "\<0[xX]\x\+[lL]\=\>" displaysyn match pythonHexNumber "\<0[xX]\>" displaysyn match pythonNumber "\<\d\+[lLjJ]\=\>" displaysyn match pythonFloat "\.\d\+\([eE][+-]\=\d\+\)\=[jJ]\=\>" displaysyn match pythonFloat "\<\d\+[eE][+-]\=\d\+[jJ]\=\>" displaysyn match pythonFloat "\<\d\+\.\d*\([eE][+-]\=\d\+\)\=[jJ]\=" displaysyn match pythonOctalError "\<0\o*[89]\d*[lL]\=\>" displaysyn match pythonHexError "\<0[xX]\X\+[lL]\=\>" displayif exists("python_highlight_builtins") && python_highlight_builtins != 0" Builtin functions, types and objectssyn keyword pythonBuiltinObj True False Ellipsis None NotImplementedsyn keyword pythonBuiltinFunc __import__ abs all any applysyn keyword pythonBuiltinFunc basestring bool buffer callablesyn keyword pythonBuiltinFunc chr classmethod cmp coerce compile complexsyn keyword pythonBuiltinFunc delattr dict dir divmod enumerate evalsyn keyword pythonBuiltinFunc execfile file filter float frozenset getattrsyn keyword pythonBuiltinfunc globals hasattr hash help hex idsyn keyword pythonBuiltinFunc input int intern isinstancesyn keyword pythonBuiltinFunc issubclass iter len list locals long map maxsyn keyword pythonBuiltinFunc min object oct open ord pow property rangesyn keyword pythonBuiltinFunc raw_input reduce reload reprsyn keyword pythonBuiltinFunc reversed round set setattrsyn keyword pythonBuiltinFunc slice sorted staticmethod str sum super tuplesyn keyword pythonBuiltinFunc type unichr unicode vars xrange zipendifif exists("python_highlight_exceptions") && python_highlight_exceptions != 0" Builtin exceptions and warningssyn keyword pythonExClass BaseExceptionsyn keyword pythonExClass Exception StandardError ArithmeticErrorsyn keyword pythonExClass LookupError EnvironmentErrorsyn keyword pythonExClass AssertionError AttributeError EOFErrorsyn keyword pythonExClass FloatingPointError GeneratorExit IOErrorsyn keyword pythonExClass ImportError IndexError KeyErrorsyn keyword pythonExClass KeyboardInterrupt MemoryError NameErrorsyn keyword pythonExClass NotImplementedError OSError OverflowErrorsyn keyword pythonExClass ReferenceError RuntimeError StopIterationsyn keyword pythonExClass SyntaxError IndentationError TabErrorsyn keyword pythonExClass SystemError SystemExit TypeErrorsyn keyword pythonExClass UnboundLocalError UnicodeErrorsyn keyword pythonExClass UnicodeEncodeError UnicodeDecodeErrorsyn keyword pythonExClass UnicodeTranslateError ValueErrorsyn keyword pythonExClass WindowsError ZeroDivisionErrorsyn keyword pythonExClass Warning UserWarning DeprecationWarningsyn keyword pythonExClass PendingDepricationWarning SyntaxWarningsyn keyword pythonExClass RuntimeWarning FutureWarning OverflowWarningsyn keyword pythonExClass ImportWarning UnicodeWarningendifif exists("python_slow_sync") && python_slow_sync != 0syn sync minlines=2000else" 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=200endifif version >= 508 || !exists("did_python_syn_inits")if version <= 508let did_python_syn_inits = 1command -nargs=+ HiLink hi link <args>elsecommand -nargs=+ HiLink hi def link <args>endifHiLink pythonStatement StatementHiLink pythonImport StatementHiLink pythonFunction FunctionHiLink pythonConditional ConditionalHiLink pythonRepeat RepeatHiLink pythonException ExceptionHiLink pythonOperator OperatorHiLink pythonDecorator DefineHiLink pythonComment CommentHiLink pythonCoding SpecialHiLink pythonRun SpecialHiLink pythonTodo TodoHiLink pythonError ErrorHiLink pythonIndentError ErrorHiLink pythonSpaceError ErrorHiLink pythonString StringHiLink pythonUniString StringHiLink pythonRawString StringHiLink pythonUniRawString StringHiLink pythonEscape SpecialHiLink pythonEscapeError ErrorHiLink pythonUniEscape SpecialHiLink pythonUniEscapeError ErrorHiLink pythonUniRawEscape SpecialHiLink pythonUniRawEscapeError ErrorHiLink pythonStrFormat SpecialHiLink pythonDocTest SpecialHiLink pythonDocTest2 SpecialHiLink pythonNumber NumberHiLink pythonHexNumber NumberHiLink pythonFloat FloatHiLink pythonOctalError ErrorHiLink pythonHexError ErrorHiLink pythonBuiltinObj StructureHiLink pythonBuiltinFunc FunctionHiLink pythonExClass Structuredelcommand HiLinkendiflet b:current_syntax = "python"