Last Updated: February 25, 2016
·
1.73K
· rane

Make vim play nice with HTML templates inside script tags

Put the following code in ~/.vim/after/syntax/html.vim. You may have to create the syntax directory.

unlet b:current_syntax
syn include @HTML $VIMRUNTIME/syntax/html.vim
syn region htmlTemplate start=+<script [^>]*type *=[^>]*text/template[^>]*>+
\                       end=+</script>+me=s-1 keepend
\                       contains=@HTML,htmlScriptTag,@htmlPreproc

This works only with script tags with type="text/template" attribute, and won't syntax highlight whatever templating language you're using inside. With something like Handlebars you might want to look elsewhere, I simply wanted to make HTML look decent in my templates.

Gist: https://gist.github.com/raine/5620562

1 Response
Add your response

Thanks! Thats great!

The only thing I am missing is auto indentation.

over 1 year ago ·