Home Explore Blog CI



neovim

6th chunk of `runtime/doc/usr_28.txt`
d69b70db09b50d66659f23d612a96be55acce7e31d87f0010000000100000ca5
 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
|-d| option does this for you.  Example: >

	:setlocal diff foldmethod=diff scrollbind nowrap foldlevel=1

Do this in every window that shows a different version of the same file.  You
will clearly see the differences between the files, while the text that didn't
change is folded.

For more details see |fold-diff|.

==============================================================================
*28.10* Which fold method to use?

All these possibilities make you wonder which method you should choose.
Unfortunately, there is no golden rule.  Here are some hints.

If there is a syntax file with folding for the language you are editing, that
is probably the best choice.  If there isn't one, you might try to write it.
This requires a good knowledge of search patterns.  It's not easy, but when
it's working you will not have to define folds manually.

Typing commands to manually fold regions can be used for unstructured text.
Then use the |:mkview| command to save and restore your folds.

The marker method requires you to change the file.  If you are sharing the
files with other people or you have to meet company standards, you might not
be allowed to add them.
   The main advantage of markers is that you can put them exactly where you
want them.  That avoids that a few lines are missed when you cut and paste
folds.  And you can add a comment about what is contained in the fold.

Folding by indent is something that works in many files, but not always very
well.  Use it when you can't use one of the other methods.  However, it is
very useful for outlining.  Then you specifically use one 'shiftwidth' for
each nesting level.

Folding with expressions can make folds in almost any structured text.  It is
quite simple to specify, especially if the start and end of a fold can easily
be recognized.
   If you use the "expr" method to define folds, but they are not exactly how
you want them, you could switch to the "manual" method.  This will not remove
the defined folds.  Then you can delete or add folds manually.

==============================================================================

Next chapter: |usr_29.txt|  Moving through programs

Copyright: see |manual-copyright|  vim:tw=78:ts=8:noet:ft=help:norl:

Title: Folding Unchanged Lines and Choosing a Folding Method
Summary
This section details using folding for unchanged lines with the 'diff' option. It demonstrates setting 'diff' to visually highlight differences by folding unchanged text. Furthermore, it gives guidelines on choosing the most suitable folding method based on the file type and editing needs, considering factors like syntax file availability, text structure, collaboration constraints, and ease of recognition for fold starts and ends. It suggests syntax folding for supported languages, manual folding for unstructured text, marker folding for precise control, indent folding for general use, and expression folding for structured text, and how manual folding can be used to correct expression folds.