Vim: Fold top level folds only

2019-03-09 00:43发布

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?

标签: vim folding
3条回答
ゆ 、 Hurt°
2楼-- · 2019-03-09 01:04

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 and zv 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.

查看更多
疯言疯语
3楼-- · 2019-03-09 01:08

Yes, you can type

:%foldc

Which closes one level of folds (outside in).

查看更多
不美不萌又怎样
4楼-- · 2019-03-09 01:21

I think you want to add set foldnestmax=1 to your $MYVIMRC.

查看更多
登录 后发表回答