Vim:仅折叠顶层折叠
我有一个很长的代码文件,其语法在 Vim 中折叠。
我知道如何打开所有折叠 (zR) 或关闭所有折叠 (zM),并且我知道如何增加或减少折叠级别 (zm, zr)。
然而,当我增加折叠级别时,最里面的折叠会关闭;相反,我希望最外面的折叠闭合,而最里面的折叠展开。可以通过打开所有折叠并手动关闭每个顶级折叠来手动完成此操作,这是令人难以置信的乏味,特别是对于我快速打开以获取代码概述的长文件。
有没有任何快捷键可以做到这一点?或者我需要创建某种 Vim 函数来做到这一点?如果是这样,怎么办?
I have a long code file with syntax folding in Vim.
I know how to open all folds (zR) or close all folds (zM), and I know how to increase or decrease the foldlevel (zm, zr).
However when I increase the foldlevel the inner most folds are closed; instead I want the outer most folds closed while the inner most are unfolded. It is possible to do this manually by opening all folds and the closing each top level fold by hand it's incredible tedious specially with long files that I open quickly to get an overview of the code.
Is there any key shortcut to do this? Or do I need to make some sort of Vim function to do this? And if so, how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您想将
set Foldnestmax=1
添加到您的$MYVIMRC
中。I think you want to add
set foldnestmax=1
to your$MYVIMRC
.是的,您可以输入
“哪个闭合一层折叠”(由外向内)。
Yes, you can type
Which closes one level of folds (outside in).
正如 Karl 所说,
foldnestmax
设置可能就是您想要的。zO
(即大写字母-o)打开所有嵌套折叠。我还发现
zx
和zv
非常有帮助。当我将
foldmethod=expr
与自定义折叠表达式一起使用时,我经常会修改该表达式,以便它只折叠我想要折叠的内容。As Karl says, the
foldnestmax
setting is probably what you want.zO
(i.e., capital-letter-o) opens all nested folds.I also find
zx
andzv
very helpful.When I use
foldmethod=expr
with a custom fold expression, I'll often modify the expression so that it only folds what I want it to fold.