comparison Misc/Vim/python.vim @ 36652:8db985b4086e legacy-trunk

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