fold level.
This gives a very quick way of "zooming out" to view the structure of the
text, move the cursor, and "zoom in" on the text again.
(B) By using |zo| and |zc| commands to open or close specific folds.
This allows opening only those folds that you want to be open, while other
folds remain closed.
This can be combined: You can first close most folds by using |zm| a few times
and then open a specific fold with |zo|. Or open all folds with |zR| and
then close specific folds with |zc|.
But you cannot manually define folds when 'foldmethod' is "indent", as that
would conflict with the relation between the indent and the fold level.
More about folding by indent in the reference manual: |fold-indent|
==============================================================================
*28.6* Folding with markers
Markers in the text are used to specify the start and end of a fold region.
This gives precise control over which lines are included in a fold. The
disadvantage is that the text needs to be modified.
Try it: >
:set foldmethod=marker
Example text, as it could appear in a C program: >
/* foobar () {{{ */
int foobar()
{
/* return a value {{{ */
return 42;
/* }}} */
}
/* }}} */
Notice that the folded line will display the text before the marker. This is
very useful to tell what the fold contains.
It's quite annoying when the markers don't pair up correctly after moving some
lines around. This can be avoided by using numbered markers. Example: >
/* global variables {{{1 */
int varA, varB;
/* functions {{{1 */
/* funcA() {{{2 */
void funcA() {}
/* funcB() {{{2 */
void funcB() {}
/* }}}1 */
At every numbered marker a fold at the specified level begins. This will make
any fold at a higher level stop here. You can just use numbered start markers
to define all folds. Only when you want to explicitly stop a fold before
another starts you need to add an end marker.
More about folding with markers in the reference manual: |fold-marker|
==============================================================================
*28.7* Folding by syntax
For each language Vim uses a different syntax file. This defines the colors
for various items in the file. If you are reading this in Vim, in a terminal
that supports colors, the colors you see are made with the "help" syntax file.
In the syntax files it is possible to add syntax items that have the "fold"
argument. These define a fold region. This requires writing a syntax 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\"),'[^>].*','',''))