At first, I use the set foldmethod=marker, and move the cursor to the { of one function, use the zf% to fold current function. But there are a lot of functions in this file. How can I fold all functions in this file? And I don't want to fold {} in the functions.
Open it in Vim, and place the cursor at the beginning of a paragraph. Make sure you're in normal mode, and type zf2j . After you press j , Vim will create a fold covering three lines — the line you started the fold on, and the next two lines.
To expand the lines, put the cursor over the fold and hit spacebar (in vim terminology, this deletes the fold). (Side note: you may want to change the look of collapsed folds.
The problem is that when you close Vim, your artfully folded code returns to its unfolded state. The solution is quite simple - when you are ready to save your folds run the :mkview command. This will save your folds in the current buffer to your viewdir ( :h viewdir ) depending on your environment.
If you :set foldmethod=syntax
the folds will be specified from the syntax definitions. If you prefer you can :set foldmethod=indent
to have the indentation define the folds.
You can close all folds with zM
. If you have nested folds and you want to fold level by level, use zm
. To open folds use zR
(all) and zr
(level by level).
If each function has its opening brace on the first column you could do:
:%g/^{/normal! zf%
Maybe it is more clear this way:
:%g /^{/ normal! zf%
the g
command selects lines according to the following pattern, and executes an ex command (here normal!
to play normal mode keystrokes).
See :help :g
and :help :normal
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With