Skip to Content

Fold in Vim

Posted on

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 fold
  • syntax – folds are defined by syntax highlighting
  • expr – folds are defined by a user-defined expression
  • marker – special characters can be manually or automatically added to your text to flag the start and end of folds
  • diff – 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
comments powered by Disqus