Vim将使用@Spell和@NoSpell集群定义Vim突出显示拼写错误的语法项。见:help spell-syntax(和的其余部分:help spell和:help syntax文件)的全部细节。
获得所需结果的快速而肮脏的解决方法是在Vim config目录中创建一个新文件.vim/after/syntax/html.vim:
syn region htmlString contained start=+"+ end=+"+ contains=htmlSpecialChar,javaScriptExpression,@htmlPreproc,@Spell
syn region htmlString contained start=+'+ end=+'+ contains=htmlSpecialChar,javaScriptExpression,@htmlPreproc,@Spell
这些行定义了HTML属性的语法突出显示,并从Vim的标准语法文件中包含的html.vim文件复制而来。然后,我将@Spell群集添加到该contains字段中,以便在每个语法项中启用拼写检查。
为了仅将此属性应用于“ title”和“ data- *”属性,需要对用于匹配项的正则表达式进行微调,并对HTML高亮的工作方式进行更广泛的编辑。这是仅适用于“标题”属性的解决方案:
syn region htmlStringSpell contained start=+title=["']+hs=s+6 end=+["']+ contains=htmlSpecialChar,javaScriptExpression,@htmlPreproc,@Spell containedin=htmlTag,ScriptTag
hi def link htmlStringSpell String
NB
- 现在,正则表达式包括
title属性的名称和偏移量,以便语法项目的这一部分不包括在突出显示中。(请参阅:help syn-pattern-offset)
- 语法项现在有了自己的名称,因此需要(i)是
containedinhtmlStrings通过其各自的contains设置包含在其中的所有语法项。(ii)有自己的突出显示。