Home Explore Blog CI



neovim

7th chunk of `runtime/doc/fold.txt`
ff4293e0237ffaf13df63e6992ef6b284afbeaf665d1a5d00000000100000ea4
 fold
		is counted as one fold.
		When a count is used, repeats the command [count] times.
		This command can be used after an |operator|.


EXECUTING COMMANDS ON FOLDS ~

:[range]foldd[oopen] {cmd}		*:foldd* *:folddo* *:folddoopen*
		Execute {cmd} on all lines that are not in a closed fold.
		When [range] is given, only these lines are used.
		Each time {cmd} is executed the cursor is positioned on the
		line it is executed for.
		This works like the ":global" command: First all lines that
		are not in a closed fold are marked.  Then the {cmd} is
		executed for all marked lines.  Thus when {cmd} changes the
		folds, this has no influence on where it is executed (except
		when lines are deleted, of course).
		Example: >
			:folddoopen s/end/loop_end/ge
<		Note the use of the "e" flag to avoid getting an error message
		where "end" doesn't match.

:[range]folddoc[losed] {cmd}			*:folddoc* *:folddoclosed*
		Execute {cmd} on all lines that are in a closed fold.
		Otherwise like ":folddoopen".

==============================================================================
3. Fold options					*fold-options*

COLORS							*fold-colors*

The colors of a closed fold are set with the Folded group |hl-Folded|.  The
colors of the fold column are set with the FoldColumn group |hl-FoldColumn|.
Example to set the colors: >

	:highlight Folded guibg=grey guifg=blue
	:highlight FoldColumn guibg=darkgrey guifg=white


FOLDLEVEL						*fold-foldlevel*

'foldlevel' is a number option: The higher the more folded regions are open.
When 'foldlevel' is 0, all folds are closed.
When 'foldlevel' is positive, some folds are closed.
When 'foldlevel' is very high, all folds are open.
'foldlevel' is applied when it is changed.  After that manually folds can be
opened and closed.
When increased, folds above the new level are opened.  No manually opened
folds will be closed.
When decreased, folds above the new level are closed.  No manually closed
folds will be opened.


FOLDTEXT						*fold-foldtext*

'foldtext' is a string option that specifies an expression.  This expression
is evaluated to obtain the text displayed for a closed fold.  Example: >

    :set foldtext=v:folddashes.substitute(getline(v:foldstart),'/\\*\\\|\\*/\\\|{{{\\d\\=','','g')

This shows the first line of the fold, with "/*", "*/" and "{{{" removed.
Note the use of backslashes to avoid some characters to be interpreted by the
":set" command.  It is much simpler to define a function and call it: >

    :set foldtext=MyFoldText()
    :function MyFoldText()
    :  let line = getline(v:foldstart)
    :  let sub = substitute(line, '/\*\|\*/\|{{{\d\=', '', 'g')
    :  return v:folddashes .. sub
    :endfunction

Evaluating 'foldtext' is done in the |sandbox|.  The current window is set to
the window that displays the line.

Errors are ignored.  For debugging set the 'debug' option to "throw".

The default value is |foldtext()|.  This returns a reasonable text for most
types of folding.  If you don't like it, you can specify your own 'foldtext'
expression.  It can use these special Vim variables:
	v:foldstart	line number of first line in the fold
	v:foldend	line number of last line in the fold
	v:folddashes	a string that contains dashes to represent the
			foldlevel.
	v:foldlevel	the foldlevel of the fold

If the result is a |List|, it is parsed and drawn like "overlay" virtual text
(see |nvim_buf_set_extmark()|), otherwise the result is converted to a string
where a TAB is replaced with a space and unprintable characters are made into
printable characters.

The resulting line is truncated to fit in the window, it never wraps.
When there is room after the text, it is filled with the character specified
by 'fillchars'.

If the 'foldtext' expression

Title: Executing Commands on Folds and Fold Options: Colors, Level, and Text
Summary
This section describes how to execute commands on lines within folds, specifically using :folddoopen and :folddoclosed. It then details the options that control fold appearance and behavior: 'foldlevel' (determining the number of open folds), 'foldtext' (defining the text displayed for closed folds, using variables like v:foldstart, v:foldend, v:folddashes, and v:foldlevel), and fold colors (configurable with the Folded and FoldColumn highlight groups).