在下面的代碼中: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 containedendfunctionautocmd BufEnter *.go call GoHtml()但是,在我保存文檔后,調用 GoImports 時 html 語法突出顯示消失了: let g:go_fmt_command = "GoImports"有沒有辦法保持嵌入的 html 突出顯示?
1 回答

蝴蝶不菲
TA貢獻1810條經驗 獲得超4個贊
最后我把它釘在了這個上面:
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 代碼。
- 1 回答
- 0 關注
- 168 瀏覽
添加回答
舉報
0/150
提交
取消