Vim: Fold top level folds only

driax picture driax · Feb 22, 2011 · Viewed 9.7k times · Source

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?

Answer

Karl Bielefeldt picture Karl Bielefeldt · Feb 22, 2011

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