猿问

GoImports 杀死 html 语法高亮

在下面的代码中:


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

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


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


料青山看我应如是
浏览 129回答 1
1回答

蝴蝶不菲

最后我把它钉在了这个上面:function! GoHtml()&nbsp; &nbsp; GoFmt&nbsp; &nbsp; if !empty(b:current_syntax)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; unlet b:current_syntax&nbsp; &nbsp; endif&nbsp; &nbsp; syn include @html syntax/html.vim&nbsp; &nbsp; syntax region htmlCode start=+<!DOCTYPE+ keepend end=+</html>+ contains=@html containedin=goRawString containedendfunctionautocmd BufEnter *.go call GoHtml()autocmd BufWrite *.go call GoHtml()execute pathogen#infect()" don't save automatically, let us handle thislet g:go_fmt_autosave = 0" for golang: automatically run GoImportslet g:go_fmt_command = "GoImports"这样我就可以按照我想要的方式混合 go 和 html 代码。
随时随地看视频慕课网APP

相关分类

Go
我要回答