gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 05:26:12 25 4
gpt4 key购买 nike

当折叠在 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。如果您的默认设置是“collapse folds”,那么您可能需要使用 zR 扩展结果。

关于vim - 是否可以使用 vim 在折叠折叠中显示嵌套部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27392059/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com