Vim 中嵌套注释折叠的语法高亮
在 Vim 中,我使用标准折叠标记 {{{
,}}}
以及折叠的命名约定(例如 {{{ collection
) 。一些命名的折叠定义了注释(例如{{{documentation
),我希望这些能够如此突出显示。所有折叠都以相同的 }}}
标记结束。
我在以下方面取得了一些成功:
syn region cComment start="{{{ documentation" end="}}}"
contains=@cCommentGroup,cCommentStartError,cSpaceError,@Spell fold
但问题是注释折叠也可以包含通用 collection
折叠,如下例所示:
{{{ documentation
{{{ collection
// some text
}}}
{{{ collection
// some text
}}}
}}}}
在这种情况下,注释在第一个 } 时停止}}
已到达,因此第二个 collection
折叠不会突出显示为注释。
contains
选项似乎不相关,因为这使得包含的折叠具有其标准突出显示。
我希望注释折叠内的任何折叠都继承注释语法,而不影响注释折叠外的默认语法。
考虑到所有折叠都具有相同的结束标记,这在 Vim 中可能吗?
In Vim, I use the standard foldmarkers {{{
,}}}
with a naming convention for the folds (e.g. {{{ collection
). Some named folds define a comment (e.g. {{{ documentation
) and I would like these to be highlighted as such. All the folds end with the same }}}
marker.
I am having some success with the following:
syn region cComment start="{{{ documentation" end="}}}"
contains=@cCommentGroup,cCommentStartError,cSpaceError,@Spell fold
but the problem is that commented folds can also contain generic collection
folds, as in the following example:
{{{ documentation
{{{ collection
// some text
}}}
{{{ collection
// some text
}}}
}}}}
In this case, the commenting stops when the first }}}
is reached, so the second collection
fold is not highlighted as a comment.
The contains
option does not seem relevant, as this makes contained folds have their standard highlighting.
I would like any fold inside a comment fold to inherit the comment syntax, without affecting their default syntax outside a comment fold.
Is this possible in Vim, given that all folds have the same endmarkers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
老实说,我不完全确定你想要什么,但似乎确实有一种方法可以区分“文档”折叠的末尾和“集合”折叠的末尾。仅当发现三个右括号作为一行中的第一个字符时,下面的代码才会结束 cComment 区域:
此外,如果您使用标记来指定折叠,则语法区域命令中的 'fold' 选项不相关。仅当您使用语法指定折叠时,将折叠与 syn-region 结合使用才有用,但事实并非如此。
I honestly am not entirely sure what you want, but there does appear to be a way to distinguish between end of your 'documentation' fold and end of your 'collection' folds. The code below will end the cComment region only when three right brackes are found as first characters in a line:
Also, the 'fold' option in your syntax region command is not relevant if you're using markers to specify folds. Using fold with syn-region is useful only if you're using syntax to specify folds, which you aren't.