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

2024-01-10

当在 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 和默认 ({{{) mark 的多个嵌套折叠:

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如果您的默认设置是“折叠折叠”。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

是否可以使用 vim 在折叠折叠中显示嵌套部分? 的相关文章

随机推荐