solarized
solarized copied to clipboard
Python highlighting in vim
Hi,
In (terminal) vim Solarized does not seem to highlight Python:
docstrings/multi-line comments literal numbers strings
Is there any interest in enabling this?
Thanks, Tom
solarized is a colorscheme, not a syntax script -- are you sure 'filetype' is being set correctly?
Thanks for the suggestion, but, yes, filetype is being set correctly.
I ended up making some ugly hacks to my python.vim syntax file to get things sort-of-working, but I'm sure there's a more correct way to do this. If anybody has got solarized to highlight strings (and numbers, and docstrings etc) without this sort of mistreatment I would be very interested to know about it. For what it's worth, here's the diff between the original python.vim (version 2.6.7 of http://www.vim.org/scripts/script.php?script_id=790) and my bastardised version:
126c126
< syn keyword pythonPreCondit import from as
---
> syn keyword pythonInclude import from as
318c318
< HiLink pythonPreCondit Include
---
> HiLink pythonPreCondit Statement
330c330
< HiLink pythonCoding Comment
---
> HiLink pythonCoding Special
338,341c338,341
< HiLink pythonString hsString
< HiLink pythonUniString hsString
< HiLink pythonRawString hsString
< HiLink pythonUniRawString hsString
---
> HiLink pythonString String
> HiLink pythonUniString String
> HiLink pythonRawString String
> HiLink pythonUniRawString String
357,361c357,361
< HiLink pythonNumber PreProc
< HiLink pythonHexNumber PreProc
< HiLink pythonOctNumber PreProc
< HiLink pythonBinNumber PreProc
< HiLink pythonFloat PreProc
---
> HiLink pythonNumber Number
> HiLink pythonHexNumber Number
> HiLink pythonOctNumber Number
> HiLink pythonBinNumber Number
> HiLink pythonFloat Float
I think the issue is that the solarized theme thunks all constants to the same color. You can see this by loading the theme and then loading the vim hilight test, e.g.:
:so $VIMRUNTIME/syntax/hitest.vim
This shows:
.....
Constant Constant String Character Number Boolean Float
.....
so numbers and strings (etc.) all end up with the same color.
This appears to be specific to solarized.
Adding:
exe "hi! Number" .s:fmt_none .s:fg_yellow .s:bg_none exe "hi! String" .s:fmt_none .s:fg_red .s:bg_none to solarized.vim helps. (Section Basic highlighting, below paragraph:exe "hi! Constants" ...., app. line 551) Choose colors as you like. Add additional lines for Float, Boolean etc. if you like.
OR add s.th. like this to solarize vim. (you need python.vim):
"python highlighting "{{{ exe "hi! pythonBuiltin" .s:fg_green .s:bg_back .s:fmt_none exe "hi! pythonOperator" .s:fg_violet .s:bg_back .s:fmt_bold exe "hi! pythonNumber" .s:fg_red .s:bg_back .s:fmt_none exe "hi! pythonString" .s:fg_yellow .s:bg_back .s:fmt_none exe "hi! pythonRawString" .s:fg_yellow .s:bg_back .s:fmt_none exe "hi! pythonStatement" .s:fg_cyan .s:bg_back .s:fmt_bold exe "hi! pythonConditional" .s:fg_blue .s:bg_back .s:fmt_bold exe "hi! pythonRepeat" .s:fg_magenta .s:bg_back .s:fmt_bold exe "hi! pythonExceptions" .s:fg_violet .s:bg_back .s:fmt_none exe "hi! pythonSpaceError" .s:fg_base1 .s:bg_orange .s:fmt_none " (activate this ^ in python.vim by: let python_space_error_highlight = 1) exe "hi! pythonDecorator" .s:fg_base2 .s:bg_back .s:fmt_none exe "hi! pythonInclude" .s:fg_yellow .s:bg_back .s:fmt_ital exe "hi! pythonDoctest" .s:fg_base01 .s:bg_back .s:fmt_none exe "hi! pythonFunction" .s:fg_orange .s:bg_back .s:fmt_bold "}}}
I don't know why this isn't included anyway.
python.vim version: " Vim syntax file " Language: Python " Maintainer: Neil Schemenauer [email protected] " Last Change: 2014 Jul 16 " Credits: Zvezdan Petkovic [email protected] " Neil Schemenauer [email protected] " Dmitry Vasiliev
I added the line (python.vim): syn keyword pythonSelf self
and to solarized.vim:
exe "hi! pythonSelf" .s:fg_base1 .s:bg_back .s:fmt_bold
Crazy that this scheme isn't Python-compatible.
Here's my attempt at offering a slightly better visual aid, loosely following @jetrock's proposition:
- vim syntax: https://raw.githubusercontent.com/mknw/.dotfiles/mknw/vim/syntax/python.vim
- vim colorscheme: https://raw.githubusercontent.com/mknw/.dotfiles/mknw/vim/colors/solarized.vim