Home Explore Blog CI



neovim

1st chunk of `runtime/doc/fold.txt`
a1ffc4ec517bc6e26dad81102525f48c2d3b8891e28c25290000000100000fa0
*fold.txt*      Nvim


		  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|

                                      Type |gO| to see the table of contents.

==============================================================================
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 make a fold out of paragraphs separated by blank lines: >
	:set foldexpr=getline(v:lnum)=~'^\\s*$'&&getline(v:lnum+1)=~'\\S'?'<1':1
This does the same: >
	:set foldexpr=getline(v:lnum-1)=~'^\\s*$'&&getline(v:lnum)=~'\\S'?'>1':1

Note that backslashes must be used to escape characters that ":set" handles
differently (space, backslash, double quote, etc., see |option-backslash|).

The most efficient is to call a function without arguments: >
	:set foldexpr=MyFoldLevel()
The function must use v:lnum.  See |expr-option-function|.

These are the conditions with which the expression is evaluated:

- The current buffer and window are set for the line.
- The variable "v:lnum" is set to the line number.

The result of foldexpr then determines the fold level as follows:
  value			meaning ~
  0			the line is not in a fold
  1, 2, ..		the line is in a fold with this level
  -1			the fold level is undefined, use the fold level of a
			line before or after this line, whichever is the
			lowest.
  "="			use fold level from the previous line
  "a1", "a2", ..	add one, two, .. to the fold level of the previous
			line, use the result for the current line
  "s1", "s2", ..	subtract one, two, .. from the fold level of the
			previous line, use the result for the next line
  "<1", "<2", ..	a fold with this level ends at this line
  ">1", ">2", ..	a fold with this level starts at this

Title: Vim Folding Reference
Summary
This section of the Vim reference manual details the folding feature, which allows you to hide and show blocks of text. It covers the different folding methods available in Vim, including manual folding, indent-based folding, expression-based folding, syntax-based folding, diff-based folding, and marker-based folding. Each method is explained with examples and considerations for customization.