Highlight python docstrings as comments (vim syntax highlighting)

后端 未结 3 962
梦毁少年i
梦毁少年i 2020-12-15 07:01

Is it possible to modify python.vim (and the corresponding colorscheme file) such that triple-quoted strings right under class and def statements (a.k.a. docstrings) will be

3条回答
  •  无人及你
    2020-12-15 08:01

    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

提交回复
热议问题