Code folding

This allows the user to manage large amounts of text while viewing only those subsections that are currently of interest.

Other names for these features include expand and collapse, code hiding, and outlining.

The folding structure typically follows the syntax tree of the program defined by the computer language.

It may also be defined by levels of indentation, or be specified explicitly using an in-band marker (saved as part of the source code) or out-of-band.

Each of these has its own distinct advantages and difficulties, and it is essentially up to the developers who create the text editor software to decide which to implement.

Text editors that provide support for multiple folding mechanisms typically allow the user to choose which is most appropriate for the file being edited.

These are desirable due to being automatic and agreeing with code structure, but may require significant work to implement, and time to compute when editing a file.

Indentation-based folding points are generally specified by the position and sequence of non-printing whitespace, such as tabs and spaces, within the text.

This convention is particularly suitable to syntaxes that have an off-side rule, so the structure largely agrees with the indent.

However, even in these cases, structure does not exactly agree with indent, such as in line continuation, and thus syntax-dependent folding is preferred.

As a manual method, token-based folding allows discretion in grouping code based on arbitrary criteria, such as "functions related to a given task", which cannot be inferred from syntactic analysis.

This allows them to be shared, but also requires their use (or preservation) by all programmers working on a particular file, and can cause friction and maintenance burden.

Folded text might be anonymous or named, and this may be preserved across editing sessions or discarded.

Unlike token-based folding, this does not change the source text – it thus is not shared with other editors of the file, and is not visible in the code.

A folding editor appeared in the occam IDE circa 1983, which was called the Inmos Transputer Development System (TDS)[7],.

Code folding example on PHP code with Vim