Mode

:set foldmethod=normal
:set fdm=normal
manualManually define fold range.
indentAutomatic make the folds based on indent.
syntaxAutomatic make the folds based on your file extension.
exprUse :set foldexpr=TODO.
markerManually define fold range and add a marker.
diffvim -d file1 file2
vimdiff file2 file2
:set diffopt=filler,context:0

Operator

zf{motion}Define fold using motion. zfiB, zfib, zfi[, zfj
{count}zFDefine fold using count. 2zF = zfj= :.,+1fo = 2:fo
:{range} foDefine fold using range. :.,+1fo = 2zF = zfj
zdDelete fold at the cursor.
zEDelete all fold in the buffer.
zoReveal fold at the cursor.
zcClose fold at the cursor.
zaToggle reveal/close at the cursor.
ziTurn fold on/off.
zrUnfold (reveal) per-level.
zmFold (close) per-level.
zRReveal all folds in the buffer.
zMClose all folds in the buffer.
zOReveal all folds from cursor’s root.
zCClose folds from cursor’s child to its root.

root
|__childA
|__childB

When you press zC while your cursor at childA it will fold to root. When you reveal root, childA is folded, childB is not.
zAToggle zO/zC.
zkUp one fold section.
zjDown one fold section.

Saving a fold

In manual mode, when you close the buffer, the fold is gone.

To save the fold the memory, use :mkview. To load from the memory, use :loadview.

To save the fold to a file, use :mkview <filename>. To load the fold from a file, use :loadview <filename>.

Fold column

:set foldcolumn=0-9
:set fdc=0-9

References:


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *