I'd like to see some nice syntax highlighting and colouring in my Python's docstrings which (of course) are valid RESt. For example:
'''
A section
=========
an example::
some code
'''
rest of python code
The closest I've got is this in my .vim/after/syntax/python.vim:
syn include syntax/rst.vim
syn region pythonDocstring start=+^\s*'''+ end=+'''+ contained
According to the documentation of syntax-include that should be sufficient to. Also note that rst.vim re-defines a bunch of python entities so I've had to comment out all sections related to code:
" syn region rstCodeBlock contained matchgroup=rstDirective
" \ start=+\%(sourcecode\|code\%(-block\)\=\)::\_s*\n\ze\z(\s\+\)+
" \ skip=+^$+
" \ end=+^\z1\@!+
" \ contains=@NoSpell
" syn cluster rstDirectives add=rstCodeBlock
" if !exists('g:rst_syntax_code_list')
[...]
Lastly, I can't use !runtime because rst.vim does nothing if the b:current_syntax variable is already defined:
if exists("b:current_syntax")
finish
endif
Despite my efforts my docstring stays the same colour as other comments, with no syntax highlighting.
I've tried also this:
syn region pythonDocstring start=+^\s*'''+ end=+'''+ contains=CONTAINED
But I only managed to change the colour of the block to be Special rather than Comment.
Perhaps I should define the pythonDocstring not to have any default colouring?
Further note: if I remove references to python raw strings in python.vim, colouring disappears but I only get the python keywords highlighted.
Update
Trying one of the solutions below with my after/syntax/python.vim file:
syn include @pythonRst syntax/rst.vim
syn region pythonDocstring start=+^\s*'''+ end=+'''+ contains=@pythonRst
Resulted in the RESt file being grayed out when opening a file with .py extension:
While opening the same file with a .rst. extension seems to work fine (just to show that I have a rest syntax file):
Note that I've tried both with and without colorscheme in my .vimrc


