Skip to content

Commit 5ffc69c

Browse files
monkoosenfnty
authored andcommitted
Add option variable for class variables
1 parent 4eee0bd commit 5ffc69c

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ let g:python_highlight_all = 1
6767
| `g:python_highlight_indent_errors` | Highlight indentation errors | `0` |
6868
| `g:python_highlight_space_errors` | Highlight trailing spaces | `0` |
6969
| `g:python_highlight_doctests` | Highlight doc-tests | `0` |
70+
| `g:python_highlight_class_vars` | Highlight class variables `self` and `cls` | `0` |
7071
| `g:python_highlight_all` | Enable all highlight options above, except for previously set. | `0` |
7172
| `g:python_highlight_file_headers_as_comments` | Highlight shebang and coding headers as comments | `0` |
7273
| `g:python_slow_sync` | Disable for slow machines | `1` |

doc/python-syntax.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ following command to your `~/.config/nvim/init.vim` or `~/.vimrc`: >
8686
`g:python_highlight_doctests` (default `0`)
8787
Highlight doc-tests
8888

89+
`g:python_highlight_class_vars` (default `0`)
90+
Highlight class variables `self` and `cls`
91+
8992
`g:python_highlight_all` (default `0`)
9093
Enable all highlight options above, except for previously set.
9194

syntax/python.vim

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,13 @@ if s:Enabled('g:python_highlight_all')
5252
call s:EnableByDefault('g:python_highlight_space_errors')
5353
call s:EnableByDefault('g:python_highlight_doctests')
5454
call s:EnableByDefault('g:python_print_as_function')
55+
call s:EnableByDefault('g:python_highlight_class_vars')
5556
endif
5657

5758
"
5859
" Keywords
5960
"
6061

61-
syn keyword pythonInstanceVariable self
62-
syn keyword pythonClassVariable cls
6362
syn keyword pythonStatement break continue del
6463
syn keyword pythonStatement exec return
6564
syn keyword pythonStatement pass yield
@@ -68,6 +67,9 @@ syn keyword pythonStatement global assert
6867
syn keyword pythonStatement lambda
6968
syn keyword pythonStatement with
7069
syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite
70+
if s:Enabled('g:python_highlight_class_vars')
71+
syn keyword pythonClassVar self cls
72+
endif
7173
syn keyword pythonRepeat for while
7274
syn keyword pythonConditional if elif else
7375
syn keyword pythonException try except finally
@@ -102,8 +104,7 @@ syn region FunctionParameters start='(\zs' end='\ze)' display contains=
102104
\ FunctionParameters,
103105
\ OptionalParameters,
104106
\ pythonRepeat,
105-
\ pythonInstanceVariable,
106-
\ pythonClassVariable,
107+
\ pythonClassVar,
107108
\ pythonConditional,
108109
\ pythonComment,
109110
\ pythonOperator,
@@ -125,7 +126,7 @@ syn region FunctionParameters start='(\zs' end='\ze)' display contains=
125126
\ pythonNone,
126127
\ pythonBuiltinFunc,
127128
\ pythonBoolean nextgroup=pythonRaiseFromStatement display contained
128-
syn match OptionalParameters /\i*\ze=/ display contained
129+
syn match OptionalParameters /\i\+\ze=/ display contained
129130
"
130131
" Decorators (new in Python 2.4)
131132
"
@@ -486,9 +487,8 @@ if v:version >= 508 || !exists('did_python_syn_inits')
486487
HiLink pythonBuiltinFunc Function
487488

488489
HiLink pythonExClass Structure
489-
HiLink pythonInstanceVariable htmlTagN
490-
HiLink pythonClassVariable htmlTagN
491-
HiLink OptionalParameters htmlTagN
490+
HiLink pythonClassVar Identifier
491+
HiLink OptionalParameters Identifier
492492

493493
delcommand HiLink
494494
endif

0 commit comments

Comments
 (0)