function! CustomSyntax()
syntax on
syntax include @HTML syntax/html.vim
syntax region htmlSnip matchgroup=SnipHTML start="html`" end="`" contains=@HTML
syntax include @JSON syntax/json.vim
syntax region jsonSnip matchgroup=SnipJSON start="json`" end="`" contains=@JSON
syntax include @CPP syntax/cpp.vim
syntax region cppSnip matchgroup=SnipCPP start="@begin=cpp@" end="@end=cpp@" contains=@CPP
endfunction
autocmd BufRead,BufNewFile * call CustomSyntax()
我希望有不同语言的多个语法区域。现在只完成了第一个。如果我删除第一个,那么下一个就会突出显示。
我期待所有区域同时突出显示
语法脚本通常有以下形式的防护:
if exists("b:current_syntax")
finish
endif
[...]
let b:current_syntax = "foobar"
在这种情况下意味着:
b:current_syntax
变量定义在syntax/html.vim
,这个问题的解决方案是在每次采购后用核武器攻击
b:current_syntax
:
function! CustomSyntax()
syntax include @HTML syntax/html.vim
unlet b:current_syntax
syntax region htmlSnip matchgroup=SnipHTML start="html`" end="`" contains=@HTML
syntax include @JSON syntax/json.vim
unlet b:current_syntax
syntax region jsonSnip matchgroup=SnipJSON start="json`" end="`" contains=@JSON
syntax include @CPP syntax/cpp.vim
unlet b:current_syntax
syntax region cppSnip matchgroup=SnipCPP start="@begin=cpp@" end="@end=cpp@" contains=@CPP
endfunction
:help syn-include
应该更清楚了。