Home Explore Blog CI



neovim

2nd chunk of `runtime/doc/usr_28.txt`
6cab20c9ea30867859b1189156eb876c5377bbce739ca4620000000100000fa1
 folds
of several levels.

If you have nested several levels deep, you can open all of them with: >

	zR

This R-educes folds until there are none left.  And you can close all folds
with: >

	zM

This folds M-ore and M-ore.

You can quickly disable the folding with the |zn| command.  Then |zN| brings
back the folding as it was.  |zi| toggles between the two.  This is a useful
way of working:
- create folds to get overview on your file
- move around to where you want to do your work
- do |zi| to look at the text and edit it
- do |zi| again to go back to moving around

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

==============================================================================
*28.3*	Working with folds

When some folds are closed, movement commands like "j" and "k" move over a
fold like it was a single, empty line.  This allows you to quickly move around
over folded text.

You can yank, delete and put folds as if it was a single line.  This is very
useful if you want to reorder functions in a program.  First make sure that
each fold contains a whole function (or a bit less) by selecting the right
'foldmethod'.  Then delete the function with "dd", move the cursor and put it
with "p".  If some lines of the function are above or below the fold, you can
use Visual selection:
- put the cursor on the first line to be moved
- hit "V" to start Visual mode
- put the cursor on the last line to be moved
- hit "d" to delete the selected lines.
- move the cursor to the new position and "p"ut the lines there.

It is sometimes difficult to see or remember where a fold is located, thus
where a |zo| command would actually work.  To see the defined folds: >

	:set foldcolumn=4

This will show a small column on the left of the window to indicate folds.
A "+" is shown for a closed fold.  A "-" is shown at the start of each open
fold and "|" at following lines of the fold.

You can use the mouse to open a fold by clicking on the "+" in the foldcolumn.
Clicking on the "-" or a "|" below it will close an open fold.

To open all folds at the cursor line use |zO|.
To close all folds at the cursor line use |zC|.
To delete a fold at the cursor line use |zd|.
To delete all folds at the cursor line use |zD|.

When in Insert mode, the fold at the cursor line is never closed.  That allows
you to see what you type!

Folds are opened automatically when jumping around or moving the cursor left
or right.  For example, the "0" command opens the fold under the cursor
(if 'foldopen' contains "hor", which is the default).  The 'foldopen' option
can be changed to open folds for specific commands.  If you want the line
under the cursor always to be open, do this: >

	:set foldopen=all

Warning: You won't be able to move onto a closed fold then.  You might want to
use this only temporarily and then set it back to the default: >

	:set foldopen&

You can make folds close automatically when you move out of it: >

	:set foldclose=all

This will re-apply 'foldlevel' to all folds that don't contain the cursor.
You have to try it out if you like how this feels.  Use |zm| to fold more and
|zr| to fold less (reduce folds).

The folding is local to the window.  This allows you to open two windows on
the same buffer, one with folds and one without folds.  Or one with all folds
closed and one with all folds open.

==============================================================================
*28.4*	Saving and restoring folds

When you abandon a file (starting to edit another one), the state of the folds
is lost.  If you come back to the same file later, all manually opened and
closed folds are back to their default.  When folds have been created
manually, all folds are gone!  To save the folds use the |:mkview| command: >

	:mkview

This will store the settings and other things that influence the view on the
file.  You can change what is stored with the 'viewoptions' option.
When you come back to the same file later, you can load the view again: >

Title: Working with and Saving/Restoring Folds in Vim
Summary
This section discusses how movement commands interact with folds, allowing quick navigation over folded text. It covers yanking, deleting, and putting folds as single lines for reordering content. The use of 'foldcolumn' is introduced to visually indicate fold locations. Commands like `zO`, `zC`, `zd`, and `zD` are explained for manipulating folds at the cursor line. Additionally, it details how folds are handled in Insert mode and how 'foldopen' and 'foldclose' options can customize fold behavior. Finally, it explains how to save and restore fold states using `:mkview` and 'viewoptions'.