💾 Archived View for gmi.noulin.net › vim › fold.gmi captured on 2022-06-12 at 07:49:50. Gemini links have been rewritten to link to archived content
View Raw
More Information
➡️ Next capture (2022-07-17)
-=-=-=-=-=-=-
- fold.txt* For Vim version 8.2. Last change: 2022 Jan 22
VIM REFERENCE MANUAL by Bram Moolenaar
Folding *Folding* *folding* *folds*
You can find an introduction on folding in chapter 28 of the user manual.
|usr_28.txt|
1. Fold methods |fold-methods|
2. Fold commands |fold-commands|
3. Fold options |fold-options|
4. Behavior of folds |fold-behavior|
{not available when compiled without the |+folding| feature}
==============================================================================
1. Fold methods *fold-methods*
The folding method can be set with the 'foldmethod' option.
When setting 'foldmethod' to a value other than "manual", all folds are
deleted and new ones created. Switching to the "manual" method doesn't remove
the existing folds. This can be used to first define the folds automatically
and then change them manually.
There are six methods to select folds:
manual manually define folds
indent more indent means a higher fold level
expr specify an expression to define folds
syntax folds defined by syntax highlighting
diff folds for unchanged text
marker folds defined by markers in the text
MANUAL *fold-manual*
Use commands to manually define the fold regions. This can also be used by a
script that parses text to find folds.
The level of a fold is only defined by its nesting. To increase the fold
level of a fold for a range of lines, define a fold inside it that has the
same lines.
The manual folds are lost when you abandon the file. To save the folds use
the |:mkview| command. The view can be restored later with |:loadview|.
INDENT *fold-indent*
The folds are automatically defined by the indent of the lines.
The foldlevel is computed from the indent of the line, divided by the
'shiftwidth' (rounded down). A sequence of lines with the same or higher fold
level form a fold, with the lines with a higher level forming a nested fold.
The nesting of folds is limited with 'foldnestmax'.
Some lines are ignored and get the fold level of the line above or below it,
whichever is lower. These are empty or white lines and lines starting
with a character in 'foldignore'. White space is skipped before checking for
characters in 'foldignore'. For C use "#" to ignore preprocessor lines.
When you want to ignore lines in another way, use the "expr" method. The
|indent()| function can be used in 'foldexpr' to get the indent of a line.
EXPR *fold-expr*
The folds are automatically defined by their foldlevel, like with the "indent"
method. The value of the 'foldexpr' option is evaluated to get the foldlevel
of a line. Examples:
This will create a fold for all consecutive lines that start with a tab: >
:set foldexpr=getline(v:lnum)[0]==\"\\t\"
This will call a function to compute the fold level: >
:set foldexpr=MyFoldLevel(v:lnum)
This will make a fold out of paragraphs separated by blank lines: >
:set foldexpr=getline(v:lnum)=~'^\\s*