Fold in Vim
Folding methods
The foldmethod option is local for each window.
manual– folds must be defined by entering commands.indent– groups of lines with the same indent form a foldsyntax– folds are defined by syntax highlightingexpr– folds are defined by a user-defined expressionmarker– special characters can be manually or automatically added to your text to flag the start and end of foldsdiff– used to fold unchanged text when viewing differences (automatically set in diff mode)
Opening & Closing folds
| Vim folding command | Use to |
|---|---|
zc |
close a fold (if the cursor is in an open fold) |
zo |
open a fold (if the cursor is in a closed fold) |
za |
(toggle) operate on one level of folding, at the cursor |
zj, zk |
moves the cursor to the next/previous fold |
zm, zr |
increases/decrease the foldlevel by one |
zM, zR |
closes/open all folds |