I am trying to adjust the reStructured text syntax highlighting in vim. I have tried several vim regexes to get highlight working for below two examples, but I am unable to.
When integrating with an existing syntax script (here: $VIMRUNTIME/syntax/rst.vim
), you need to consider the existing syntax groups. :syn list
shows all active groups, but it's easier when you install the SyntaxAttr.vim - Show syntax highlighting attributes of character under cursor plugin. (I maintain an extended fork.)
On your example headings, I see that the .. item::
part is matched by rstExplicitMarkup
, and the remainder (what you want to highlight) by rstExDirective
.
Assuming that you want to integrate with (and not completely override) these, you need your syntax group to be contained inside the latter. This can be done via containedin=rstExDirective
.
Another pitfall is that \zs
limits the highlighting, but internally still matches the whole text. In combination with syntax highlighting, this means that the existing rstExplicitMarkup
prevents a match of your pattern. If you use a positive lookbehind (:help /\@<=) instead, it'll work:
syn match rstHeading /\%([.+].*[:+] \)\@<=.*/ containedin=rstExDirective
Of course, to actually see any highlighting, you also need to define or link a highlight group to your new syntax group:
hi link rstHeading Title