Code folding is a feature of some text editors, source code editors, and IDEs that allows the user to selectively hide and display – "fold" – sections of a currently-edited file as a part of routine edit operations. This allows the user to manage large amounts of text while viewing only those subsections of the text that are specifically relevant at any given time.
Identification of folds can be automatic, most often based on the syntax of the computer language in question, indentation, or manual, either based on an in-band marker (saved as part of the source code) or specified out-of-band, only within the editor.
Many editors provide disclosure widgets for code folding in a sidebar, next to line numbers, indicated for example by a triangle that points sideways (if collapsed) or down (if expanded), or by a [-]
box for collapsible (expanded) text, and a [+]
box for expandable (collapsed) text. This feature is commonly used by some computer programmers to manage source code files, and is also frequently used in data comparison, to only view the changed text.
Text folding is a similar feature used in folding editors and outliners, but is used for ordinary text and, if automatic, is based on syntax of human languages, particularly paragraphs, or section levels, rather than syntax of a computer language. Another variant of code folding is "data folding", which is implemented in some hex editors and is used to structure a binary file or hide inaccessible data sections in a RAM-editor. There are various alternative terms for such features, including "expand and collapse", "code hiding", and "outlining".
Probably the first folding editor was the 1974 Structured Programming Facility (SPF) editor for IBM 370 mainframes which could hide lines based on their indentation. It displayed on character-mapped 3270 terminals. It was very useful for prolix languages like COBOL. It evolved into the Interactive System Productivity Facility(ISPF)).