GoImports 取消 html 语法高亮

GoImports kills html syntax highlighting

在下面的代码中:

var rootTemplate = template.Must(template.New("root").Parse(`
<!DOCTYPE html>
<html>
<head>
 /SNIP/
</html>
`))

我可以使用此函数将 html 部分突出显示为 html:

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()

但是在我保存文档后,html 语法突出显示在调用 GoImports 时消失了:let g:go_fmt_command = "GoImports"

有没有办法让嵌入的 html 突出显示?

最后我确定了这一点:

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"

这样我就可以混合 go 并且 html 代码按照我想要的方式着色。