In the following go code:
var rootTemplate = template.Must(template.New("root").Parse(`
<!DOCTYPE html>
<html>
<head>
/SNIP/
</html>
`))
I am able to make the html part highlighted as html with this function:
function! GoHtml()
if !empty(b:current_syntax)
unlet b:current_syntax
endif
syn include @html syntax/html.vim
syntax region htmlCode start=+<!DOCTYPE+ keepend end=+</html>+ contains=@html containedIn=goRawString contained
endfunction
autocmd BufEnter *.go call GoHtml()
However after I saved the document, the html syntax highlighting disappears when calling GoImports: let g:go_fmt_command = "GoImports"
Is there a way to keep embeeded html highlighted?
Finally I nailed it to this:
function! GoHtml()
GoFmt
if !empty(b:current_syntax)
unlet b:current_syntax
endif
syn include @html syntax/html.vim
syntax region htmlCode start=+<!DOCTYPE+ keepend end=+</html>+ contains=@html containedin=goRawString contained
endfunction
autocmd BufEnter *.go call GoHtml()
autocmd BufWrite *.go call GoHtml()
execute pathogen#infect()
" don't save automatically, let us handle this
let g:go_fmt_autosave = 0
" for golang: automatically run GoImports
let g:go_fmt_command = "GoImports"
That way I can have mixed go and html code colored the way I want.