是否可以使用 vim 在折叠折叠中显示嵌套部分



当折叠在 vim 中折叠时,所有嵌套的标题都被隐藏起来,这样你就看不到里面的内容了。我很好奇是否有人知道是否有可能或有foldtext功能的解决方案(或通过另一种方法),可以在折叠折叠时显示折叠内的部分。

我正在寻找可以显示更多折叠的东西:

+ --   2000 TopSection1                                    " Fold Level 1
+ ---   500 TopSection1 : ChildSection1                    " Fold Level 2
+ ----   50 TopSection1 : ChildSection1 : BottomSection1   " Fold Level 3
+ ---   100 TopSection1 : ChildSection2 : BottomSection1   " Fold Level 2
+ --    500 TopSection2                                    " Fold Level 1
+ ---    25 TopSection2 : ChildSection1                    " Fold Level 2

我一直在四处挖掘,但还没有找到一种方法来完成这项工作(或者如果可能的话)。有什么建议吗?

以下命令获取所有折叠行,中间没有正文文本:

:g/{{{/

它适用于下面的示例,其中包含多个嵌套折叠,其中包含 foldmethod=marker 和默认 ({{{) 标记:

Text 1/*{{{*/
some text here
subtext 1.1/*{{{*/
some text here
subsubtext 1.1.1/*{{{*/
some text here/*}}}*/
subsubtext 1.1.2/*{{{*/
some text here/*}}}*//*}}}*/
subtext 1.2/*{{{*/
some text here
subsubtext 1.2.1/*{{{*/
some text here/*}}}*/
subsubtext 1.2.2/*{{{*/
some text here/*}}}*//*}}}*//*}}}*/
Text 2/*{{{*/
some text here
subtext 2.1/*{{{*/
some text here
subsubtext 2.1.1/*{{{*/
some text here/*}}}*/
subsubtext 2.1.2/*{{{*/
some text here/*}}}*//*}}}*/
subtext 2.2/*{{{*/
some text here
subsubtext 2.2.1/*{{{*/
some text here/*}}}*/
subsubtext 2.2.2/*{{{*/
some text here/*}}}*//*}}}*//*}}}*/

运行 :g/{{{/命令后,你会得到这个:

Text 1/*{{{*/
subtext 1.1/*{{{*/
subsubtext 1.1.1/*{{{*/
subsubtext 1.1.2/*{{{*/
subtext 1.2/*{{{*/
subsubtext 1.2.1/*{{{*/
subsubtext 1.2.2/*{{{*/
Text 2/*{{{*/
subtext 2.1/*{{{*/
subsubtext 2.1.1/*{{{*/
subsubtext 2.1.2/*{{{*/
subtext 2.2/*{{{*/
subsubtext 2.2.1/*{{{*/
subsubtext 2.2.2/*{{{*/

如果要将结果重定向到新缓冲区,则可以运行:

:let @a='' | execute 'g/{{{/y A' | new | setlocal bt=nofile | put! a

它拉动 {{{ 模式以注册"a",打开一个新的缓冲区并粘贴 reg。然后,如果默认值为"折叠折叠",则可能需要用zR扩展结果。

您将不得不使用foldtext,而且还要解析该部分的内容以获取要显示的内容。

我使用 zr 和 zm 普通命令打开和关闭另一个折叠关卡。我同意 zr 还将在折叠级别和子级别之间显示文本;因此,它不能完全解决您的问题。似乎更好的方法是使用 foldmethod=syntax,然后根据 foldmethod 语法的正则表达式使用全局 (g) 命令过滤所有折叠行。

最新更新