Vim HereDoc Highlighting

Viewed 1267

I want to get syntax highlighting inside of a bash heredoc. In addition, I want bash variable dereference and command substitution highlighting in the heredoc.

Using these instructions as a starting point, I was able to add variable dereferencing by examining sh.vim. I imagine you could accomplish command substitution in a similar fashion.

let s:bcs = b:current_syntax

unlet b:current_syntax
syntax include @YAML syntax/yaml.vim

syntax region hereDocYAML matchgroup=Statement start=/<<-\?\s*\z(YML\)/ end=/^\s*\z1/ contains=@YAML,hereDocDeref,hereDocDerefSimple

syn match  hereDocDerefSimple  "\$\%(\h\w*\|\d\)"
syn region hereDocDeref  matchgroup=PreProc start="\${" end="}"  contains=@shDerefList,shDerefVarArray

hi def link hereDocDeref PreProc
hi def link hereDocDerefSimple PreProc

My problem is, this doesn't appear to work in any sort of block (if, function, for, etc.). For example:

highlighting example

The only thing I know is that this is not an indentation problem. Changing indentation has no effect, and using indentation outside of a block works properly.

1 Answers
Related