Vim/Folding
From Debuntu
Folding is a feature of Vim that allows to hide a block of text under a fold. This is pretty usefull when dealing with lengthly code files as it gave a better overview of the code by hiding bit of code that are not really meaningful at a specific time.
Contents |
Creating/Deleting Folds
Creating
Visual Mode
In visual mode, select the bit of text you want to fold and type:
zf
Motion Mode
In Motion Mode, you can create a fold like this:
zf5j
This will create a fold from the current line to 5 line below.
Escape Mode
In Escape Mode, folds can be created like that:
:.,+3fo
Will fold from the current line until 3 lines below. The syntax is:
{range}fo[ld]
Deleting
To delete one fold at the cursor, use:
zd
To delete all folds:
zE
Opening and Closing Folds
Opening
To open one fold:
zo
To open all folds at the cursor recursively:
zO
To open all folds:
zR
Closing
To close one fold:
zc
To close all folds at the cursor recursively:
zC
To close all folds in the window:
zM
Some more tips
Closing from the current { to the matching }. Make sure your cursor is on the opening curly bracket and run:
zfa}
This also works with any other brackets.
It also works backward by being on a closing curly bracket } and typing:
zfa{
Folding from cursor to matching_string:
zf/matching_string