From WikEmacs
Jump to: navigation, search

Folding is a way to hide and show text in an emacs buffer, i.e. to do code folding. For example, we can do the same thing than with org-mode but with source code.

You may look at the differences between narrowing and hiding text in Emacs :


outline is a built in mode to cycle visibility and edit the code structure. You should check it out !

Evil users

evil-mode users have pre-defined keys: use za to toggle visibility, zc (close), zm (close all), zr (open all). They are an interface to other folding packages, most notably hideshow. The value of the variable evil-fold-list determines which backend is used for which major or minor modes, and what functions are available for those backends.

You might also like vimish-fold: it works with regions, it is persistent, it has mouse support, avy support, …

Third party packages


yafolding, in melpa, is based on indentation.


origami works well with languages that use braces to delimit blocks.

Fold this region

To fold the active region, see fold-this (in Melpa).