Vim 语法:特定区域之间的拼写检查

Vim syntax: Spell checking between certain regions

我正在尝试为这种名为 Sugar Cube 2 的语言创建一个语法文件。您可以在这里找到更多相关信息:http://www.motoslave.net/sugarcube/2/docs/macros.html

一般来说,我不想在宏之间进行拼写检查(例如,<<if $myVariable>>)。但是,你可以制作自己的宏,而我恰好制作了一个这样的宏:

<<myDescription "This is a string that should be in english">>

如您所见,"english" 应该大写,所以在这种情况下进行拼写检查会很有用。

我已经知道 vim 的 syntax。它是 keywordmatchregion@NoSpell 等。但我真的很难将这些概念放在一起来实现我想要的:Spell checking between a specific macros ,但不是所有的宏。这是我的想法,它利用了 syn-priority:

中描述的概念
syn match macroDelimiter "\v(<<|>>)"
" there's much more keywords than this
syn keyword macroKeywords contained if elseif else myDescription
syn region mostMacros matchgroup=macroKeywords start="<<" end=">>" contains=@NoSpell
syn region myMacro matchgroup=macroKeywords start="<<myDescription" end=">>"

我的意思是...我试过了并且有效。我不喜欢的一件事是 myDescription 像尖括号一样突出显示。我也不喜欢单词 myDescription 本身的拼写检查方式,但我可以接受。有办法解决这些问题吗?


这将解决上述问题:

set spell spelllang=en_us
syn match macroDelimiter "\v(<<|>>)"
" there's much more keywords than this
syn keyword macroKeywords contained if elseif else myDescription
syn region macroString start=+"+ end=+"+ skip=+\"+
syn region mostMacros matchgroup=macroDelimiter start="<<" end=">>" contains=@NoSpell,macroString
"Notice how this is commented out
"syn region myMacro matchgroup=macroDelimiter start="<<myDescription" end=">>"

hi link macroKeywords Keyword
hi link macroDelimiter Constant

但它增加了一个主要问题:还有其他带有字符串的宏。 <<link>><<goto>> 宏也有字符串。但我不想拼写检查那里的字符串。

要去除 myDescriptionmatchgroup 突出显示,但仍强制执行匹配,请通过 \ze:

结束组的开始
syn region myMacro matchgroup=macroKeywords start="<<\zemyDescription" end=">>" contains=@Spell

这将为 myDescription 本身启用拼写。为避免这种情况,您必须将其语法从 keyword 更改为 match,以便向其添加 contains=@NoSpell

syn match myDescription "myDescription" contains=@NoSpell
syn region myMacro matchgroup=macroKeywords start="<<\zemyDescription" end=">>" contains=@Spell,myDescription