/ vim

Fold and unfold in Vim

There are a couple of foldmethods, but we're going to talk about manual and indent here.

Change foldmethod by setting :set foldmethod=manual or :set foldmethod=indent. (:set fdm=manual works as well)

Command keys

This list is not exhausive, but is enough to get started.
zf Insert markers
za Toggle fold
zc, zm, zM Close, more fold, close all
zo, zr, zR Open, reduce fold, open all

Manual

Default folds are indicated by {{{ and }}}.
You can change them with :set foldmarkers=/*,*/ or :set fmr=/*,*/ for example.

You can select the lines to fold in command mode, then use zf to insert the markers.
Or zf5j to fold 5 lines down. zf5k folds 5 lines up.

Indent

When you set foldmethod to indent, Vim is able to fold text based on the level of indents.
Superhandy feature when working with python or yaml files.
Doesn't little your files with markers too.

Fold and unfold in Vim
Share this