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 buffer
- `zo` - open the fold(where your cursor is positioned)
- `zR` - open all folds on current buffer
- `zj` - cursor is moved to next fold
- `zk` - cursor is moved to previous fold
---
tags: #vim , #fold
sources:
- [vim fandom folding guide](https://vim.fandom.com/wiki/Folding)
- [javascript folding on vim](https://medium.com/vim-drops/javascript-folding-on-vim-119c70d2e872)