Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions runtime/doc/syntax.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3222,7 +3222,7 @@ Pascal. Use this if you don't use assembly and Pascal: >

PYTHON *python.vim* *ft-python-syntax*

There are six options to control Python syntax highlighting.
There are seven options to control Python syntax highlighting.

For highlighted numbers: >
:let python_no_number_highlight = 1
Expand All @@ -3242,10 +3242,13 @@ The first option implies the second one.
For highlighted trailing whitespace and mix of spaces and tabs: >
:let python_space_error_highlight = 1

For highlighted built-in constants distinguished from other keywords:
:let python_constant_highlight = 1

If you want all possible Python highlighting: >
:let python_highlight_all = 1
This has the same effect as setting python_space_error_highlight and
unsetting all the other ones.
This has the same effect as setting python_space_error_highlight,
python_constant_highlight and unsetting all the other ones.

If you use Python 2 or straddling code (Python 2 and 3 compatible),
you can enforce the use of an older syntax file with support for
Expand Down
13 changes: 13 additions & 0 deletions runtime/syntax/python.vim
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
" let python_no_exception_highlight = 1
" let python_no_number_highlight = 1
" let python_space_error_highlight = 1
" let python_constant_highlight = 1
"
" All the options above can be switched on together.
"
Expand Down Expand Up @@ -85,6 +86,7 @@ if exists("python_highlight_all")
unlet python_no_number_highlight
endif
let python_space_error_highlight = 1
let python_constant_highlight = 1
endif

" Keep Python keywords in alphabetical order inside groups for easy
Expand Down Expand Up @@ -367,6 +369,13 @@ if exists("python_space_error_highlight")
syn match pythonSpaceError display "\t\+ "
endif

" Built-in Constants
" https://docs.python.org/3/library/constants.html
if exists("python_constant_highlight")
syn keyword pythonBoolean False True
syn keyword pythonConstant None NotImplemented Ellipsis __debug__
endif

" Do not spell doctests inside strings.
" Notice that the end of a string, either ''', or """, will end the contained
" doctest too. Thus, we do *not* need to have it as an end pattern.
Expand Down Expand Up @@ -434,6 +443,10 @@ if !exists("python_no_doctest_highlight")
hi def link pythonDoctest Special
hi def link pythonDoctestValue Define
endif
if exists("python_constant_highlight")
hi def link pythonBoolean Boolean
hi def link pythonConstant Constant
endif

let b:current_syntax = "python"

Expand Down
20 changes: 20 additions & 0 deletions runtime/syntax/testdir/dumps/python_constants_default_00.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
>#+0#0000e05#ffffff0| |B|u|i|l|t|-|i|n| |C|o|n|s|t|a|n|t|s| +0#0000000&@54
|#+0#0000e05&| |h|t@1|p|s|:|/@1|d|o|c|s|.|p|y|t|h|o|n|.|o|r|g|/|3|/|l|i|b|r|a|r|y|/|c|o|n|s|t|a|n|t|s|.|h|t|m|l| +0#0000000&@24
@75
|#+0#0000e05&| |V|I|M|_|T|E|S|T|_|S|E|T|U|P| |u|n|l|e|t| |g|:|p|y|t|h|o|n|_|c|o|n|s|t|a|n|t|_|h|i|g|h|l|i|g|h|t| +0#0000000&@24
|t|e|s|t| |=| |F+0#00e0e07&|a|l|s|e| +0#0000000&@62
|t|e|s|t| |=| |T+0#00e0e07&|r|u|e| +0#0000000&@63
|t|e|s|t| |=| |N+0#00e0e07&|o|n|e| +0#0000000&@63
|t|e|s|t| |=| |N+0#00e0e07&|o|t|I|m|p|l|e|m|e|n|t|e|d| +0#0000000&@53
|t|e|s|t| |=| |E+0#00e0e07&|l@1|i|p|s|i|s| +0#0000000&@59
|t|e|s|t| |=| |_+0#00e0e07&@1|d|e|b|u|g|_@1| +0#0000000&@58
@75
|~+0#4040ff13&| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
| +0#0000000&@56|1|,|1| @10|A|l@1|
20 changes: 20 additions & 0 deletions runtime/syntax/testdir/dumps/python_constants_highlight_00.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
>#+0#0000e05#ffffff0| |B|u|i|l|t|-|i|n| |C|o|n|s|t|a|n|t|s| +0#0000000&@54
|#+0#0000e05&| |h|t@1|p|s|:|/@1|d|o|c|s|.|p|y|t|h|o|n|.|o|r|g|/|3|/|l|i|b|r|a|r|y|/|c|o|n|s|t|a|n|t|s|.|h|t|m|l| +0#0000000&@24
@75
|#+0#0000e05&| |V|I|M|_|T|E|S|T|_|S|E|T|U|P| |l|e|t| |g|:|p|y|t|h|o|n|_|c|o|n|s|t|a|n|t|_|h|i|g|h|l|i|g|h|t| |=| |1| +0#0000000&@22
|t|e|s|t| |=| |F+0#e000002&|a|l|s|e| +0#0000000&@62
|t|e|s|t| |=| |T+0#e000002&|r|u|e| +0#0000000&@63
|t|e|s|t| |=| |N+0#e000002&|o|n|e| +0#0000000&@63
|t|e|s|t| |=| |N+0#e000002&|o|t|I|m|p|l|e|m|e|n|t|e|d| +0#0000000&@53
|t|e|s|t| |=| |E+0#e000002&|l@1|i|p|s|i|s| +0#0000000&@59
|t|e|s|t| |=| |_+0#e000002&@1|d|e|b|u|g|_@1| +0#0000000&@58
|~+0#4040ff13&| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
| +0#0000000&@56|1|,|1| @10|A|l@1|
11 changes: 11 additions & 0 deletions runtime/syntax/testdir/input/python_constants_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Built-in Constants
# https://docs.python.org/3/library/constants.html

# VIM_TEST_SETUP unlet g:python_constant_highlight
test = False
test = True
test = None
test = NotImplemented
test = Ellipsis
test = __debug__

10 changes: 10 additions & 0 deletions runtime/syntax/testdir/input/python_constants_highlight.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Built-in Constants
# https://docs.python.org/3/library/constants.html

# VIM_TEST_SETUP let g:python_constant_highlight = 1
test = False
test = True
test = None
test = NotImplemented
test = Ellipsis
test = __debug__
Loading