links: 010 Vim MOC
Folding in Vim
To activate folding, you will need to set the ‘foldmethod’ option
The foldmethod option (a.k.a fdm ) is local to each window and determines what kind of folding applies to the current window.
Vim supports multiple types of folding
- Manual Folding (folds must be defined by entering commands)
- Indent Folding ()
- Syntax Folding
- Indent Folding with manual folds
- Folding by expression
- Folding with markers
- Diff Folding
For example if you want to set foldmethod to syntax add following to .vimrc file
set foldmethod=syntax
Manual folding
Indent Folding
Syntax folding
In order to fold based on syntax you have to enable it in the following way
let javaScript_fold=1
let typescript_fold=1
search for syntax file options for other languages name and add them to .vimrc file in order to enable syntax folding
Usage
zc- close the fold (where your cursor is positioned)zM- close all folds on current bufferzo- open the fold(where your cursor is positioned)zR- open all folds on current bufferzj- cursor is moved to next foldzk- cursor is moved to previous fold
sources: