在下面的go代码中:
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:let g:go_fmt_command = "GoImports"时,html语法突出显示就消失了。
是否有一种方法来保持内嵌html的高亮显示?
发布于 2016-03-25 17:31:34
最后,我认为:
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代码混合起来,按我想要的方式着色。
https://stackoverflow.com/questions/35951440
复制相似问题