123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. " Vim syntax file
  2. " Language: Python
  3. " Maintainer: Dmitry Vasiliev <dima@hlabs.spb.ru>
  4. " URL: http://www.hlabs.spb.ru/vim/python.vim
  5. " Last Change: 2008-09-22
  6. " Filenames: *.py
  7. " Version: 2.6.2
  8. "
  9. " Based on python.vim (from Vim 6.1 distribution)
  10. " by Neil Schemenauer <nas@python.ca>
  11. "
  12. " Thanks:
  13. "
  14. " Jeroen Ruigrok van der Werven
  15. " for the idea to highlight erroneous operators
  16. " Pedro Algarvio
  17. " for the patch to enable spell checking only for the right spots
  18. " (strings and comments)
  19. " John Eikenberry
  20. " for the patch fixing small typo
  21. "
  22. " Options:
  23. "
  24. " For set option do: let OPTION_NAME = 1
  25. " For clear option do: let OPTION_NAME = 0
  26. "
  27. " Option names:
  28. "
  29. " For highlight builtin functions:
  30. " python_highlight_builtins
  31. "
  32. " For highlight standard exceptions:
  33. " python_highlight_exceptions
  34. "
  35. " For highlight string formatting:
  36. " python_highlight_string_formatting
  37. "
  38. " For highlight str.format syntax:
  39. " python_highlight_string_format
  40. "
  41. " For highlight string.Template syntax:
  42. " python_highlight_string_templates
  43. "
  44. " For highlight indentation errors:
  45. " python_highlight_indent_errors
  46. "
  47. " For highlight trailing spaces:
  48. " python_highlight_space_errors
  49. "
  50. " For highlight doc-tests:
  51. " python_highlight_doctests
  52. "
  53. " If you want all Python highlightings above:
  54. " python_highlight_all
  55. " (This option not override previously set options)
  56. "
  57. " For fast machines:
  58. " python_slow_sync
  59. "
  60. " For "print" builtin as function:
  61. " python_print_as_function
  62. " For version 5.x: Clear all syntax items
  63. " For version 6.x: Quit when a syntax file was already loaded
  64. if version < 600
  65. syntax clear
  66. elseif exists("b:current_syntax")
  67. finish
  68. endif
  69. if exists("python_highlight_all") && python_highlight_all != 0
  70. " Not override previously set options
  71. if !exists("python_highlight_builtins")
  72. let python_highlight_builtins = 1
  73. endif
  74. if !exists("python_highlight_exceptions")
  75. let python_highlight_exceptions = 1
  76. endif
  77. if !exists("python_highlight_string_formatting")
  78. let python_highlight_string_formatting = 1
  79. endif
  80. if !exists("python_highlight_string_format")
  81. let python_highlight_string_format = 1
  82. endif
  83. if !exists("python_highlight_string_templates")
  84. let python_highlight_string_templates = 1
  85. endif
  86. if !exists("python_highlight_indent_errors")
  87. let python_highlight_indent_errors = 1
  88. endif
  89. if !exists("python_highlight_space_errors")
  90. let python_highlight_space_errors = 1
  91. endif
  92. if !exists("python_highlight_doctests")
  93. let python_highlight_doctests = 1
  94. endif
  95. endif
  96. " Keywords
  97. syn keyword pythonStatement break continue del
  98. syn keyword pythonStatement exec return
  99. syn keyword pythonStatement pass raise
  100. syn keyword pythonStatement global assert
  101. syn keyword pythonStatement lambda yield
  102. syn keyword pythonStatement with
  103. syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite
  104. syn match pythonFunction "[a-zA-Z_][a-zA-Z0-9_]*" display contained
  105. syn keyword pythonRepeat for while
  106. syn keyword pythonConditional if elif else
  107. syn keyword pythonImport import from as
  108. syn keyword pythonException try except finally
  109. syn keyword pythonOperator and in is not or
  110. if !exists("python_print_as_function") || python_print_as_function == 0
  111. syn keyword pythonStatement print
  112. endif
  113. " Decorators (new in Python 2.4)
  114. syn match pythonDecorator "@" display nextgroup=pythonFunction skipwhite
  115. " Comments
  116. syn match pythonComment "#.*$" display contains=pythonTodo,@Spell
  117. syn match pythonRun "\%^#!.*$"
  118. syn match pythonCoding "\%^.*\(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$"
  119. syn keyword pythonTodo TODO FIXME XXX contained
  120. " Errors
  121. syn match pythonError "\<\d\+\D\+\>" display
  122. syn match pythonError "[$?]" display
  123. syn match pythonError "[&|]\{2,}" display
  124. syn match pythonError "[=]\{3,}" display
  125. " TODO: Mixing spaces and tabs also may be used for pretty formatting multiline
  126. " statements. For now I don't know how to work around this.
  127. if exists("python_highlight_indent_errors") && python_highlight_indent_errors != 0
  128. syn match pythonIndentError "^\s*\( \t\|\t \)\s*\S"me=e-1 display
  129. endif
  130. " Trailing space errors
  131. if exists("python_highlight_space_errors") && python_highlight_space_errors != 0
  132. syn match pythonSpaceError "\s\+$" display
  133. endif
  134. " Strings
  135. syn region pythonString start=+[bB]\='+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonEscape,pythonEscapeError,@Spell
  136. syn region pythonString start=+[bB]\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonEscape,pythonEscapeError,@Spell
  137. syn region pythonString start=+[bB]\="""+ end=+"""+ keepend contains=pythonEscape,pythonEscapeError,pythonDocTest2,pythonSpaceError,@Spell
  138. syn region pythonString start=+[bB]\='''+ end=+'''+ keepend contains=pythonEscape,pythonEscapeError,pythonDocTest,pythonSpaceError,@Spell
  139. syn match pythonEscape +\\[abfnrtv'"\\]+ display contained
  140. syn match pythonEscape "\\\o\o\=\o\=" display contained
  141. syn match pythonEscapeError "\\\o\{,2}[89]" display contained
  142. syn match pythonEscape "\\x\x\{2}" display contained
  143. syn match pythonEscapeError "\\x\x\=\X" display contained
  144. syn match pythonEscape "\\$"
  145. " Unicode strings
  146. syn region pythonUniString start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,@Spell
  147. syn region pythonUniString start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,@Spell
  148. syn region pythonUniString start=+[uU]"""+ end=+"""+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
  149. syn region pythonUniString start=+[uU]'''+ end=+'''+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
  150. syn match pythonUniEscape "\\u\x\{4}" display contained
  151. syn match pythonUniEscapeError "\\u\x\{,3}\X" display contained
  152. syn match pythonUniEscape "\\U\x\{8}" display contained
  153. syn match pythonUniEscapeError "\\U\x\{,7}\X" display contained
  154. syn match pythonUniEscape "\\N{[A-Z ]\+}" display contained
  155. syn match pythonUniEscapeError "\\N{[^A-Z ]\+}" display contained
  156. " Raw strings
  157. syn region pythonRawString start=+[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell
  158. syn region pythonRawString start=+[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell
  159. syn region pythonRawString start=+[rR]"""+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell
  160. syn region pythonRawString start=+[rR]'''+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell
  161. syn match pythonRawEscape +\\['"]+ display transparent contained
  162. " Unicode raw strings
  163. syn region pythonUniRawString start=+[uU][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell
  164. syn region pythonUniRawString start=+[uU][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell
  165. syn region pythonUniRawString start=+[uU][rR]"""+ end=+"""+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest2,pythonSpaceError,@Spell
  166. syn region pythonUniRawString start=+[uU][rR]'''+ end=+'''+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest,pythonSpaceError,@Spell
  167. syn match pythonUniRawEscape "\([^\\]\(\\\\\)*\)\@<=\\u\x\{4}" display contained
  168. syn match pythonUniRawEscapeError "\([^\\]\(\\\\\)*\)\@<=\\u\x\{,3}\X" display contained
  169. if exists("python_highlight_string_formatting") && python_highlight_string_formatting != 0
  170. " String formatting
  171. syn match pythonStrFormatting "%\(([^)]\+)\)\=[-#0 +]*\d*\(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
  172. syn match pythonStrFormatting "%[-#0 +]*\(\*\|\d\+\)\=\(\.\(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
  173. endif
  174. if exists("python_highlight_string_format") && python_highlight_string_format != 0
  175. " str.format syntax
  176. syn match pythonStrFormat "{\([a-zA-Z_][a-zA-Z0-9_]*\|\d\+\)\(\.[a-zA-Z_][a-zA-Z0-9_]*\|\[\(\d\+\|[^!:\}]\+\)\]\)*\(![rs]\)\=\(:\({\([a-zA-Z_][a-zA-Z0-9_]*\|\d\+\)}\|\([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*\(\.\d\+\)\=[bcdeEfFgGnoxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
  177. endif
  178. if exists("python_highlight_string_templates") && python_highlight_string_templates != 0
  179. " String templates
  180. syn match pythonStrTemplate "\$\(\$\|{[a-zA-Z_][a-zA-Z0-9_]*}\|[a-zA-Z_][a-zA-Z0-9_]*\)" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
  181. endif
  182. if exists("python_highlight_doctests") && python_highlight_doctests != 0
  183. " DocTests
  184. syn region pythonDocTest start="^\s*>>>" end=+'''+he=s-1 end="^\s*$" contained
  185. syn region pythonDocTest2 start="^\s*>>>" end=+"""+he=s-1 end="^\s*$" contained
  186. endif
  187. " Numbers (ints, longs, floats, complex)
  188. syn match pythonHexError "\<0[xX]\x*[g-zG-Z]\x*[lL]\=\>" display
  189. syn match pythonHexNumber "\<0[xX]\x\+[lL]\=\>" display
  190. syn match pythonOctNumber "\<0[oO]\o\+[lL]\=\>" display
  191. syn match pythonBinNumber "\<0[bB][01]\+[lL]\=\>" display
  192. syn match pythonNumber "\<\d\+[lLjJ]\=\>" display
  193. syn match pythonFloat "\.\d\+\([eE][+-]\=\d\+\)\=[jJ]\=\>" display
  194. syn match pythonFloat "\<\d\+[eE][+-]\=\d\+[jJ]\=\>" display
  195. syn match pythonFloat "\<\d\+\.\d*\([eE][+-]\=\d\+\)\=[jJ]\=" display
  196. syn match pythonOctError "\<0[oO]\=\o*[8-9]\d*[lL]\=\>" display
  197. syn match pythonBinError "\<0[bB][01]*[2-9]\d*[lL]\=\>" display
  198. if exists("python_highlight_builtins") && python_highlight_builtins != 0
  199. " Builtin functions, types and objects
  200. syn keyword pythonBuiltinObj True False Ellipsis None NotImplemented
  201. syn keyword pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__
  202. syn keyword pythonBuiltinFunc __import__ abs all any apply
  203. syn keyword pythonBuiltinFunc basestring bin bool buffer bytearray bytes callable
  204. syn keyword pythonBuiltinFunc chr classmethod cmp coerce compile complex
  205. syn keyword pythonBuiltinFunc delattr dict dir divmod enumerate eval
  206. syn keyword pythonBuiltinFunc execfile file filter float format frozenset getattr
  207. syn keyword pythonBuiltinFunc globals hasattr hash help hex id
  208. syn keyword pythonBuiltinFunc input int intern isinstance
  209. syn keyword pythonBuiltinFunc issubclass iter len list locals long map max
  210. syn keyword pythonBuiltinFunc min next object oct open ord
  211. syn keyword pythonBuiltinFunc pow property range
  212. syn keyword pythonBuiltinFunc raw_input reduce reload repr
  213. syn keyword pythonBuiltinFunc reversed round set setattr
  214. syn keyword pythonBuiltinFunc slice sorted staticmethod str sum super tuple
  215. syn keyword pythonBuiltinFunc type unichr unicode vars xrange zip
  216. if exists("python_print_as_function") && python_print_as_function != 0
  217. syn keyword pythonBuiltinFunc print
  218. endif
  219. endif
  220. if exists("python_highlight_exceptions") && python_highlight_exceptions != 0
  221. " Builtin exceptions and warnings
  222. syn keyword pythonExClass BaseException
  223. syn keyword pythonExClass Exception StandardError ArithmeticError
  224. syn keyword pythonExClass LookupError EnvironmentError
  225. syn keyword pythonExClass AssertionError AttributeError BufferError EOFError
  226. syn keyword pythonExClass FloatingPointError GeneratorExit IOError
  227. syn keyword pythonExClass ImportError IndexError KeyError
  228. syn keyword pythonExClass KeyboardInterrupt MemoryError NameError
  229. syn keyword pythonExClass NotImplementedError OSError OverflowError
  230. syn keyword pythonExClass ReferenceError RuntimeError StopIteration
  231. syn keyword pythonExClass SyntaxError IndentationError TabError
  232. syn keyword pythonExClass SystemError SystemExit TypeError
  233. syn keyword pythonExClass UnboundLocalError UnicodeError
  234. syn keyword pythonExClass UnicodeEncodeError UnicodeDecodeError
  235. syn keyword pythonExClass UnicodeTranslateError ValueError
  236. syn keyword pythonExClass WindowsError ZeroDivisionError
  237. syn keyword pythonExClass Warning UserWarning BytesWarning DeprecationWarning
  238. syn keyword pythonExClass PendingDepricationWarning SyntaxWarning
  239. syn keyword pythonExClass RuntimeWarning FutureWarning
  240. syn keyword pythonExClass ImportWarning UnicodeWarning
  241. endif
  242. if exists("python_slow_sync") && python_slow_sync != 0
  243. syn sync minlines=2000
  244. else
  245. " This is fast but code inside triple quoted strings screws it up. It
  246. " is impossible to fix because the only way to know if you are inside a
  247. " triple quoted string is to start from the beginning of the file.
  248. syn sync match pythonSync grouphere NONE "):$"
  249. syn sync maxlines=200
  250. endif
  251. if version >= 508 || !exists("did_python_syn_inits")
  252. if version <= 508
  253. let did_python_syn_inits = 1
  254. command -nargs=+ HiLink hi link <args>
  255. else
  256. command -nargs=+ HiLink hi def link <args>
  257. endif
  258. HiLink pythonStatement Statement
  259. HiLink pythonImport Statement
  260. HiLink pythonFunction Function
  261. HiLink pythonConditional Conditional
  262. HiLink pythonRepeat Repeat
  263. HiLink pythonException Exception
  264. HiLink pythonOperator Operator
  265. HiLink pythonDecorator Define
  266. HiLink pythonComment Comment
  267. HiLink pythonCoding Special
  268. HiLink pythonRun Special
  269. HiLink pythonTodo Todo
  270. HiLink pythonError Error
  271. HiLink pythonIndentError Error
  272. HiLink pythonSpaceError Error
  273. HiLink pythonString String
  274. HiLink pythonUniString String
  275. HiLink pythonRawString String
  276. HiLink pythonUniRawString String
  277. HiLink pythonEscape Special
  278. HiLink pythonEscapeError Error
  279. HiLink pythonUniEscape Special
  280. HiLink pythonUniEscapeError Error
  281. HiLink pythonUniRawEscape Special
  282. HiLink pythonUniRawEscapeError Error
  283. HiLink pythonStrFormatting Special
  284. HiLink pythonStrFormat Special
  285. HiLink pythonStrTemplate Special
  286. HiLink pythonDocTest Special
  287. HiLink pythonDocTest2 Special
  288. HiLink pythonNumber Number
  289. HiLink pythonHexNumber Number
  290. HiLink pythonOctNumber Number
  291. HiLink pythonBinNumber Number
  292. HiLink pythonFloat Float
  293. HiLink pythonOctError Error
  294. HiLink pythonHexError Error
  295. HiLink pythonBinError Error
  296. HiLink pythonBuiltinObj Structure
  297. HiLink pythonBuiltinFunc Function
  298. HiLink pythonExClass Structure
  299. delcommand HiLink
  300. endif
  301. let b:current_syntax = "python"