Home Explore Blog CI



neovim

5th chunk of `runtime/doc/usr_28.txt`
2858cf87de28478f88e4fd3d6028220815842f37005d555b00000001000008bf
 file
and adding these items in it.  That's not so easy to do.  But once it's done,
all folding happens automatically.
   Here we'll assume you are using an existing syntax file.  Then there is
nothing more to explain.  You can open and close folds as explained above.
The folds will be created and deleted automatically when you edit the file.

More about folding by syntax in the reference manual: |fold-syntax|

==============================================================================
*28.8*	Folding by expression

This is similar to folding by indent, but instead of using the indent of a
line a user function is called to compute the fold level of a line.  You can
use this for text where something in the text indicates which lines belong
together.  An example is an e-mail message where the quoted text is indicated
by a ">" before the line.  To fold these quotes use this: >

	:set foldmethod=expr
	:set foldexpr=strlen(substitute(substitute(getline(v:lnum),'\\s','',\"g\"),'[^>].*','',''))

You can try it out on this text:

> quoted text he wrote
> quoted text he wrote
> > double quoted text I wrote
> > double quoted text I wrote

Explanation for the 'foldexpr' used in the example (inside out):
   getline(v:lnum)			gets the current line
   substitute(...,'\\s','','g')		removes all white space from the line
   substitute(...,'[^>].*','','')	removes everything after leading '>'s
   strlen(...)				counts the length of the string, which
					is the number of '>'s found

Note that a backslash must be inserted before every space, double quote and
backslash for the ":set" command.  If this confuses you, do >

	:set foldexpr

to check the actual resulting value.  To correct a complicated expression, use
the command-line completion: >

	:set foldexpr=<Tab>

Where <Tab> is a real Tab.  Vim will fill in the previous value, which you can
then edit.

When the expression gets more complicated you should put it in a function and
set 'foldexpr' to call that function.

More about folding by expression in the reference manual: |fold-expr|

==============================================================================
*28.9*	Folding unchanged lines

This is useful when you set the 'diff' option in the same window.  The

Title: Folding by Syntax and Expression
Summary
This section describes two folding methods. The first is folding by syntax, which relies on syntax files to define fold regions automatically. The second is folding by expression, where a user-defined function calculates the fold level of a line, allowing for custom folding based on content like quoted text in emails. An example is provided for folding email quotes using a 'foldexpr' that counts the number of '>' characters at the start of each line. The text also advises on using a function for complex expressions and covers how to check and correct the 'foldexpr' value.