5

I use python and in python, three quotation marks in a row

"""

or

'''

signify a block-comment, and a normal comment is just a hashtag. (#) I want comments to be colored grey and strings to be colored orange. I am using the colorscheme murphy. I made a murphy-mine.vim file and I added this to it

hi Comment term=bold     ctermfg=Grey     guifg=Grey
hi String  term=bold     ctermfg=LightRed guifg=Orange

But gvim sees """ and ''' as a string in python syntax rather than treating it as a comment (block comment). Is there a way for me to tell gvim to see """ and ''' as a comment / block comment rather than a string?

Ingo Karkat
  • 23,523

2 Answers2

5

You can put the following into ~/.vim/after/syntax/python.vim (taken from here:

" Highlight docstrings as comments, not string.
syn region pythonDocstring  start=+^\s*[uU]\?[rR]\?"""+ end=+"""+ keepend excludenl contains=pythonEscape,@Spell,pythonDoctest,pythonDocTest2,pythonSpaceError
syn region pythonDocstring  start=+^\s*[uU]\?[rR]\?'''+ end=+'''+ keepend excludenl contains=pythonEscape,@Spell,pythonDoctest,pythonDocTest2,pythonSpaceError

hi def link pythonDocstring pythonComment
Ingo Karkat
  • 23,523
0

PEP 257 prescribes to use """triple double quotes""" for docstrings. It's not obligatory to include '''triple single quotes''' or "single double quotes" into docstrings. There is one difficulty that we have class docstrings, function docstrings, module docstrings, attribute docstrings and additional docstrings. That's why I decided that it's easier to consider docstring as following:

syn region pythonDocString start=+^\s*"""+ end=+"""+ keepend contains=...

And then:

HiLink pythonDocString        Comment

You may see examples in this script (search pythonDocString): https://github.com/andbar-ru/python-syntax/blob/master/syntax/python.vim

Andrey
  • 101