Brett Cannon | a4fe182 | 2006-02-25 14:52:53 +0000 | [diff] [blame] | 1 | " Auto-generated Vim syntax file for Python |
| 2 | " |
| 3 | " To use: copy or symlink to ~/.vim/syntax/python.vim |
| 4 | |
| 5 | |
| 6 | if exists("b:current_syntax") |
| 7 | finish |
| 8 | endif |
| 9 | |
| 10 | if exists("python_highlight_all") |
| 11 | let python_highlight_numbers = 1 |
| 12 | let python_highlight_builtins = 1 |
| 13 | let python_highlight_exceptions = 1 |
| 14 | let python_highlight_space_errors = 1 |
| 15 | endif |
| 16 | |
Brett Cannon | 20e192b | 2006-03-01 20:53:08 +0000 | [diff] [blame] | 17 | syn keyword pythonStatement as assert break continue del except exec finally |
| 18 | syn keyword pythonStatement global lambda pass print raise return try with |
| 19 | syn keyword pythonStatement yield |
Brett Cannon | a4fe182 | 2006-02-25 14:52:53 +0000 | [diff] [blame] | 20 | |
| 21 | syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite |
| 22 | |
| 23 | syn match pythonFunction "[a-zA-Z_][a-zA-Z0-9_]*" contained |
| 24 | |
| 25 | syn keyword pythonRepeat for while |
| 26 | |
| 27 | syn keyword pythonConditional if elif else |
| 28 | |
| 29 | syn keyword pythonOperator and in is not or |
| 30 | |
| 31 | syn keyword pythonPreCondit import from |
| 32 | |
| 33 | syn match pythonComment "#.*$" contains=pythonTodo |
| 34 | |
| 35 | syn keyword pythonTodo TODO FIXME XXX contained |
| 36 | |
| 37 | syn region pythonString matchgroup=Normal start=+[uU]\='+ end=+'+ skip=+\\\\\|\\'+ contains=pythonEscape |
| 38 | syn region pythonString matchgroup=Normal start=+[uU]\="+ end=+"+ skip=+\\\\\|\\"+ contains=pythonEscape |
| 39 | syn region pythonString matchgroup=Normal start=+[uU]\="""+ end=+"""+ contains=pythonEscape |
| 40 | syn region pythonString matchgroup=Normal start=+[uU]\='''+ end=+'''+ contains=pythonEscape |
| 41 | syn region pythonString matchgroup=Normal start=+[uU]\=[rR]'+ end=+'+ skip=+\\\\\|\\'+ |
| 42 | syn region pythonString matchgroup=Normal start=+[uU]\=[rR]"+ end=+"+ skip=+\\\\\|\\"+ |
| 43 | syn region pythonString matchgroup=Normal start=+[uU]\=[rR]"""+ end=+"""+ |
| 44 | syn region pythonString matchgroup=Normal start=+[uU]\=[rR]'''+ end=+'''+ |
| 45 | |
| 46 | syn match pythonEscape +\\[abfnrtv\'"\\]+ contained |
| 47 | syn match pythonEscape "\\\o\{1,3}" contained |
| 48 | syn match pythonEscape "\\x\x\{2}" contained |
| 49 | syn match pythonEscape "\(\\u\x\{4}\|\\U\x\{8}\)" contained |
| 50 | |
| 51 | syn match pythonEscape "\\$" |
| 52 | |
| 53 | |
| 54 | if exists("python_highlight_numbers") |
| 55 | syn match pythonNumber "\<0x\x\+[Ll]\=\>" |
| 56 | syn match pythonNumber "\<\d\+[LljJ]\=\>" |
| 57 | syn match pythonNumber "\.\d\+\([eE][+-]\=\d\+\)\=[jJ]\=\>" |
| 58 | syn match pythonNumber "\<\d\+\.\([eE][+-]\=\d\+\)\=[jJ]\=\>" |
| 59 | syn match pythonNumber "\<\d\+\.\d\+\([eE][+-]\=\d\+\)\=[jJ]\=\>" |
| 60 | |
| 61 | endif |
| 62 | |
| 63 | |
| 64 | if exists("python_highlight_builtins") |
| 65 | syn keyword pythonBuiltin unichr all set abs vars int __import__ unicode |
Neal Norwitz | ce96f69 | 2006-03-17 06:49:51 +0000 | [diff] [blame^] | 66 | syn keyword pythonBuiltin enumerate reduce exit issubclass |
| 67 | syn keyword pythonBuiltin divmod file Ellipsis isinstance open any |
Brett Cannon | a4fe182 | 2006-02-25 14:52:53 +0000 | [diff] [blame] | 68 | syn keyword pythonBuiltin locals help filter basestring slice copyright min |
Neal Norwitz | ce96f69 | 2006-03-17 06:49:51 +0000 | [diff] [blame^] | 69 | syn keyword pythonBuiltin super sum tuple hex execfile long id chr |
Brett Cannon | a4fe182 | 2006-02-25 14:52:53 +0000 | [diff] [blame] | 70 | syn keyword pythonBuiltin complex bool zip pow dict True oct NotImplemented |
| 71 | syn keyword pythonBuiltin map None float hash getattr buffer max reversed |
| 72 | syn keyword pythonBuiltin object quit len repr callable credits setattr |
| 73 | syn keyword pythonBuiltin eval frozenset sorted ord __debug__ hasattr |
Neal Norwitz | ce96f69 | 2006-03-17 06:49:51 +0000 | [diff] [blame^] | 74 | syn keyword pythonBuiltin delattr False license classmethod type |
| 75 | syn keyword pythonBuiltin list iter reload range globals |
Brett Cannon | a4fe182 | 2006-02-25 14:52:53 +0000 | [diff] [blame] | 76 | syn keyword pythonBuiltin staticmethod str property round dir cmp |
| 77 | |
| 78 | endif |
| 79 | |
| 80 | |
| 81 | if exists("python_highlight_exceptions") |
| 82 | syn keyword pythonException GeneratorExit ImportError RuntimeError |
| 83 | syn keyword pythonException UnicodeTranslateError MemoryError StopIteration |
| 84 | syn keyword pythonException PendingDeprecationWarning EnvironmentError |
| 85 | syn keyword pythonException LookupError OSError DeprecationWarning |
Brett Cannon | 20e192b | 2006-03-01 20:53:08 +0000 | [diff] [blame] | 86 | syn keyword pythonException UnicodeError UnicodeEncodeError |
| 87 | syn keyword pythonException FloatingPointError ReferenceError NameError |
| 88 | syn keyword pythonException OverflowWarning IOError SyntaxError |
Brett Cannon | a4fe182 | 2006-02-25 14:52:53 +0000 | [diff] [blame] | 89 | syn keyword pythonException FutureWarning SystemExit Exception EOFError |
| 90 | syn keyword pythonException StandardError ValueError TabError KeyError |
| 91 | syn keyword pythonException ZeroDivisionError SystemError |
| 92 | syn keyword pythonException UnicodeDecodeError IndentationError |
| 93 | syn keyword pythonException AssertionError TypeError IndexError |
| 94 | syn keyword pythonException RuntimeWarning KeyboardInterrupt UserWarning |
| 95 | syn keyword pythonException SyntaxWarning UnboundLocalError ArithmeticError |
| 96 | syn keyword pythonException Warning NotImplementedError AttributeError |
Brett Cannon | 20e192b | 2006-03-01 20:53:08 +0000 | [diff] [blame] | 97 | syn keyword pythonException OverflowError BaseException |
Brett Cannon | a4fe182 | 2006-02-25 14:52:53 +0000 | [diff] [blame] | 98 | |
| 99 | endif |
| 100 | |
| 101 | |
| 102 | if exists("python_highlight_space_errors") |
| 103 | syn match pythonSpaceError display excludenl "\S\s\+$"ms=s+1 |
| 104 | syn match pythonSpaceError display " \+\t" |
| 105 | syn match pythonSpaceError display "\t\+ " |
| 106 | |
| 107 | endif |
| 108 | |
| 109 | |
| 110 | hi def link pythonStatement Statement |
| 111 | hi def link pythonStatement Statement |
| 112 | hi def link pythonFunction Function |
| 113 | hi def link pythonRepeat Repeat |
| 114 | hi def link pythonConditional Conditional |
| 115 | hi def link pythonOperator Operator |
| 116 | hi def link pythonPreCondit PreCondit |
| 117 | hi def link pythonComment Comment |
| 118 | hi def link pythonTodo Todo |
| 119 | hi def link pythonString String |
| 120 | hi def link pythonEscape Special |
| 121 | hi def link pythonEscape Special |
| 122 | |
| 123 | if exists("python_highlight_numbers") |
| 124 | hi def link pythonNumber Number |
| 125 | endif |
| 126 | |
| 127 | if exists("python_highlight_builtins") |
| 128 | hi def link pythonBuiltin Function |
| 129 | endif |
| 130 | |
| 131 | if exists("python_highlight_exceptions") |
| 132 | hi def link pythonException Exception |
| 133 | endif |
| 134 | |
| 135 | if exists("python_highlight_space_errors") |
| 136 | hi def link pythonSpaceError Error |
| 137 | endif |
| 138 | |
| 139 | |
| 140 | " Uncomment the 'minlines' statement line and comment out the 'maxlines' |
| 141 | " statement line; changes behaviour to look at least 2000 lines previously for |
| 142 | " syntax matches instead of at most 200 lines |
| 143 | syn sync match pythonSync grouphere NONE "):$" |
| 144 | syn sync maxlines=200 |
| 145 | "syn sync minlines=2000 |
| 146 | |
| 147 | let b:current_syntax = "python" |