Home Explore Blog CI



neovim

4th chunk of `runtime/doc/fold.txt`
bcaec0ea1f264a6228041e8cd60fe67ab4ff678180504fb50000000100000faa
 given by the marker:
1. If a marker with the same fold level is encountered, the previous fold
   ends and another fold with the same level starts.
2. If a marker with a higher fold level is found, a nested fold is started.
3. If a marker with a lower fold level is found, all folds up to and including
   this level end and a fold with the specified level starts.

The number indicates the fold level.  A zero cannot be used (a marker with
level zero is ignored).  You can use "}}}" with a digit to indicate the level
of the fold that ends.  The fold level of the following line will be one less
than the indicated level.  Note that Vim doesn't look back to the level of the
matching marker (that would take too much time).  Example: >

	{{{1
	fold level here is 1
	{{{3
	fold level here is 3
	}}}3
	fold level here is 2

You can also use matching pairs of "{{{" and "}}}" markers to define folds.
Each "{{{" increases the fold level by one, each "}}}" decreases the fold
level by one.  Be careful to keep the markers matching!  Example: >

	{{{
	fold level here is 1
	{{{
	fold level here is 2
	}}}
	fold level here is 1

You can mix using markers with a number and without a number.  A useful way of
doing this is to use numbered markers for large folds, and unnumbered markers
locally in a function.  For example use level one folds for the sections of
your file like "structure definitions", "local variables" and "functions".
Use level 2 markers for each definition and function,  Use unnumbered markers
inside functions.  When you make changes in a function to split up folds, you
don't have to renumber the markers.

The markers can be set with the 'foldmarker' option.  It is recommended to
keep this at the default value of "{{{,}}}", so that files can be exchanged
between Vim users.  Only change it when it is required for the file (e.g., it
contains markers from another folding editor, or the default markers cause
trouble for the language of the file).

							*fold-create-marker*
"zf" can be used to create a fold defined by markers.  Vim will insert the
markers for you.  Vim will append the start and end marker, as specified with
'foldmarker'.  The markers are appended to the end of the line.
'commentstring' is used if it isn't empty.
This does not work properly when:
- The line already contains a marker with a level number.  Vim then doesn't
  know what to do.
- Folds nearby use a level number in their marker which gets in the way.
- The line is inside a comment, 'commentstring' isn't empty and nested
  comments don't work.  For example with C: adding `/* {{{ */` inside a comment
  will truncate the existing comment.  Either put the marker before or after
  the comment, or add the marker manually.
Generally it's not a good idea to let Vim create markers when you already have
markers with a level number.

							*fold-delete-marker*
"zd" can be used to delete a fold defined by markers.  Vim will delete the
markers for you.  Vim will search for the start and end markers, as specified
with 'foldmarker', at the start and end of the fold.  When the text around the
marker matches with 'commentstring', that text is deleted as well.
This does not work properly when:
- A line contains more than one marker and one of them specifies a level.
  Only the first one is removed, without checking if this will have the
  desired effect of deleting the fold.
- The marker contains a level number and is used to start or end several folds
  at the same time.

==============================================================================
2. Fold commands				*fold-commands* *E490*

All folding commands start with "z".  Hint: the "z" looks like a folded piece
of paper, if you look at it from the side.


CREATING AND DELETING FOLDS ~
							*zf* *E350*
zf{motion}  or
{Visual}zf	Operator to create a fold.
		This only works when 'foldmethod' is "manual" or "marker".
		The new fold will be closed for the "manual" method.
		'foldenable' will be set.
		Also see |fold-create-marker|.

Title: More on Marker-Based Folding and Fold Commands
Summary
This section elaborates on using markers for folding in Vim, including how different level numbers affect fold creation and nesting. It explains how to use matching pairs of '{{{' and '}}}' and how to mix numbered and unnumbered markers. It then describes the 'zf' command for creating folds by inserting markers, and the 'zd' command for deleting folds by removing markers, noting the limitations of these commands. Finally, it introduces fold commands that start with "z", including "zf" for creating folds.