/usr/share/doc/vim-doc/html/fold.html is in vim-doc 2:7.4.1689-3ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 | <HTML>
<HEAD>
<META HTTP-EQUIV="Content-type" content="text/html; charset=ISO-8859-1">
<TITLE>Vim documentation: fold</TITLE>
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>Vim documentation: fold</H1>
<A NAME="top"></A>
<A HREF="index.html">main help file</A>
<HR>
<PRE>
*<A NAME="fold.txt"></A><B>fold.txt</B>* For Vim version 7.4. Last change: 2016 Jan 02
VIM REFERENCE MANUAL by <A HREF="intro.html#Bram">Bram</A> <A HREF="intro.html#Moolenaar">Moolenaar</A>
<A HREF="#Folding">Folding</A> *<A NAME="Folding"></A><B>Folding</B>* *<A NAME="folding"></A><B>folding</B>* *<A NAME="folds"></A><B>folds</B>*
You can find an introduction on <A HREF="#folding">folding</A> in chapter 28 of the user manual.
|<A HREF="usr_28.html">usr_28.txt</A>|
1. Fold methods |<A HREF="#fold-methods">fold-methods</A>|
2. Fold commands |<A HREF="#fold-commands">fold-commands</A>|
3. Fold options |<A HREF="#fold-options">fold-options</A>|
4. Behavior of <A HREF="#folds">folds</A> |<A HREF="#fold-behavior">fold-behavior</A>|
{Vi has no Folding}
{not available when compiled without the |<A HREF="various.html#+folding">+folding</A>| feature}
==============================================================================
1. Fold methods *<A NAME="fold-methods"></A><B>fold-methods</B>*
The <A HREF="#folding">folding</A> method can be set with the <A HREF="options.html#'foldmethod'">'foldmethod'</A> option.
When setting <A HREF="options.html#'foldmethod'">'foldmethod'</A> to a value other than "manual", all <A HREF="#folds">folds</A> are
deleted and new ones created. Switching to the "manual" method doesn't remove
the existing <A HREF="#folds">folds</A>. This can be used to first define the <A HREF="#folds">folds</A> automatically
and then change them manually.
There are six methods to select <A HREF="#folds">folds</A>:
manual manually define <A HREF="#folds">folds</A>
indent more indent means a higher fold level
<A HREF="eval.html#expr">expr</A> specify an <A HREF="eval.html#expression">expression</A> to define <A HREF="#folds">folds</A>
<A HREF="syntax.html#syntax">syntax</A> <A HREF="#folds">folds</A> defined by <A HREF="syntax.html#syntax">syntax</A> highlighting
<A HREF="diff.html#diff">diff</A> <A HREF="#folds">folds</A> for unchanged text
marker <A HREF="#folds">folds</A> defined by markers in the text
MANUAL *<A NAME="fold-manual"></A><B>fold-manual</B>*
Use commands to manually define the fold regions. This can also be used by a
<A HREF="usr_41.html#script">script</A> that parses text to find <A HREF="#folds">folds</A>.
The level of a fold is only defined by its nesting. To increase the fold
level of a fold for a range of lines, define a fold inside <A HREF="motion.html#it">it</A> that has the
same lines.
The manual <A HREF="#folds">folds</A> are lost when you <A HREF="editing.html#abandon">abandon</A> the file. To save the <A HREF="#folds">folds</A> use
the |<A HREF="starting.html#:mkview">:mkview</A>| command. The view can be restored later with |<A HREF="starting.html#:loadview">:loadview</A>|.
INDENT *<A NAME="fold-indent"></A><B>fold-indent</B>*
The <A HREF="#folds">folds</A> are automatically defined by the indent of the lines.
The foldlevel is computed from the indent of the line, divided by the
<A HREF="options.html#'shiftwidth'">'shiftwidth'</A> (rounded down). A sequence of lines with the same or higher fold
level form a fold, with the lines with a higher level forming a nested fold.
The nesting of <A HREF="#folds">folds</A> is limited with <A HREF="options.html#'foldnestmax'">'foldnestmax'</A>.
Some lines are ignored and get the fold level of the line above or below <A HREF="motion.html#it">it</A>,
whichever is lower. These are empty or white lines and lines starting
with a character in <A HREF="options.html#'foldignore'">'foldignore'</A>. White space is skipped before checking for
characters in <A HREF="options.html#'foldignore'">'foldignore'</A>. For C use "<A HREF="pattern.html##">#</A>" to ignore preprocessor lines.
When you want to ignore lines in another way, use the '<A HREF="eval.html#expr">expr</A>' method. The
|<A HREF="eval.html#indent()">indent()</A>| function can be used in <A HREF="options.html#'foldexpr'">'foldexpr'</A> to get the indent of a line.
EXPR *<A NAME="fold-expr"></A><B>fold-expr</B>*
The <A HREF="#folds">folds</A> are automatically defined by their foldlevel, like with the "indent"
method. The value of the <A HREF="options.html#'foldexpr'">'foldexpr'</A> option is evaluated to get the foldlevel
of a line. Examples:
This will create a fold for all consecutive lines that start with a <A HREF="intro.html#tab">tab</A>:
<B> :set foldexpr=getline(v:lnum)[0]==\"\\t\"</B>
This will call a function to compute the fold level:
<B> :set foldexpr=MyFoldLevel(v:lnum)</B>
This will make a fold out of paragraphs separated by blank lines:
<B> :set foldexpr=getline(v:lnum)=~'^\\s*$'&&getline(v:lnum+1)=~'\\S'?'<1':1</B>
this does the same:
<B> :set foldexpr=getline(v:lnum-1)=~'^\\s*$'&&getline(v:lnum)=~'\\S'?'>1':1</B>
Note that backslashes must be used to <A HREF="intro.html#escape">escape</A> characters that "<A HREF="options.html#:set">:set</A>" handles
differently (space, backslash, double <A HREF="change.html#quote">quote</A>, etc., see |<A HREF="options.html#option-backslash">option-backslash</A>|).
These are the conditions with which the <A HREF="eval.html#expression">expression</A> is evaluated:
- The current buffer and <A HREF="windows.html#window">window</A> are set for the line.
- The variable "<A HREF="eval.html#v:lnum">v:lnum</A>" is set to the line number.
- The result is used for the fold level in this way:
<B><FONT COLOR="PURPLE"> value meaning </FONT></B>
0 the line is not in a fold
1, 2, .. the line is in a fold with this level
-1 the fold level is undefined, use the fold level of a
line before or after this line, whichever is the
lowest.
"<A HREF="change.html#=">=</A>" use fold level from the previous line
"a1", "a2", .. add one, two, .. to the fold level of the previous
line, use the result for the current line
"s1", "s2", .. subtract one, two, .. from the fold level of the
previous line, use the result for the next line
"<1", "<2", .. a fold with this level ends at this line
">1", ">2", .. a fold with this level starts at this line
It is not required to <A HREF="motion.html#mark">mark</A> the start (end) of a fold with ">1" ("<1"), a fold
will also start (end) when the fold level is higher (lower) than the fold
level of the previous line.
There must be no side effects from the <A HREF="eval.html#expression">expression</A>. The text in the buffer,
cursor position, the search patterns, <A HREF="options.html#options">options</A> etc. must not be changed.
You can change and restore them if you are careful.
If there is some error in the <A HREF="eval.html#expression">expression</A>, or the resulting value isn't
recognized, there is no error message and the fold level will be zero.
For debugging the <A HREF="options.html#'debug'">'debug'</A> option can be set to "msg", the error <A HREF="message.html#messages">messages</A> will
be visible then.
Note: Since the <A HREF="eval.html#expression">expression</A> has to be evaluated for every line, this fold
method can be very slow!
Try to avoid the "<A HREF="change.html#=">=</A>", "<A HREF="insert.html#a">a</A>" and "<A HREF="change.html#s">s</A>" return values, since Vim often has to search
backwards for a line for which the fold level is defined. This can be slow.
An example of using "a1" and "s1": For a multi-line C comment, a line
containing "/*" would return "a1" to start a fold, and a line containing "*/"
would return "s1" to end the fold after that line:
<B> if match(thisline, '/\*') >= 0</B>
<B> return 'a1'</B>
<B> elseif match(thisline, '\*/') >= 0</B>
<B> return 's1'</B>
<B> else</B>
<B> return '='</B>
<B> endif</B>
However, this won't work for single line comments, strings, etc.
|<A HREF="eval.html#foldlevel()">foldlevel()</A>| can be useful to compute a fold level relative to a previous
fold level. But note that <A HREF="eval.html#foldlevel()">foldlevel()</A> may return -1 if the level is not known
yet. And <A HREF="motion.html#it">it</A> returns the level at the start of the line, while a fold might
end in that line.
It may happened that <A HREF="#folds">folds</A> are not updated properly. You can use |<A HREF="#zx">zx</A>| or |<A HREF="#zX">zX</A>|
to force updating <A HREF="#folds">folds</A>.
SYNTAX *<A NAME="fold-syntax"></A><B>fold-syntax</B>*
A fold is defined by <A HREF="syntax.html#syntax">syntax</A> items that have the "fold" argument. |<A HREF="syntax.html#:syn-fold">:syn-fold</A>|
The fold level is defined by nesting <A HREF="#folds">folds</A>. The nesting of <A HREF="#folds">folds</A> is limited
with <A HREF="options.html#'foldnestmax'">'foldnestmax'</A>.
Be careful to specify proper <A HREF="syntax.html#syntax">syntax</A> syncing. If this is not done right, <A HREF="#folds">folds</A>
may differ from the displayed highlighting. This is especially relevant when
using patterns that match more than one line. In <A HREF="change.html#case">case</A> of doubt, try using
brute-force syncing:
<B> :syn sync fromstart</B>
DIFF *<A NAME="fold-diff"></A><B>fold-diff</B>*
The <A HREF="#folds">folds</A> are automatically defined for text that is not part of a change or
close to a change.
This method only works properly when the <A HREF="options.html#'diff'">'diff'</A> option is set for the current
<A HREF="windows.html#window">window</A> and changes are being displayed. Otherwise the whole buffer will be
one big fold.
The <A HREF="options.html#'diffopt'">'diffopt'</A> option can be used to specify the context. That is, the number
of lines between the fold and a change that are not included in the fold. For
example, to use a context of 8 lines:
<B> :set diffopt=filler,context:8</B>
The default context is six lines.
When <A HREF="options.html#'scrollbind'">'scrollbind'</A> is also set, Vim will attempt to keep the same <A HREF="#folds">folds</A> open in
other <A HREF="diff.html#diff">diff</A> <A HREF="windows.html#windows">windows</A>, so that the same text is visible.
MARKER *<A NAME="fold-marker"></A><B>fold-marker</B>*
Markers in the text tell where <A HREF="#folds">folds</A> start and end. This allows you to
precisely specify the <A HREF="#folds">folds</A>. This will allow <A HREF="change.html#deleting">deleting</A> and putting a fold,
without the risk of including the wrong lines. The <A HREF="options.html#'foldtext'">'foldtext'</A> option is
normally set such that the text before the marker shows up in the folded line.
This makes <A HREF="motion.html#it">it</A> possible to give a name to the fold.
Markers can have a level included, or can use matching pairs. Including a
level is easier, you don't have to add end markers and avoid problems with
non-matching marker pairs. Example:
<B> /* global variables {{{1 */</B>
<B> int varA, varB;</B>
<B> /* functions {{{1 */</B>
<B> /* funcA() {{{2 */</B>
<B> void funcA() {}</B>
<B> /* funcB() {{{2 */</B>
<B> void funcB() {}</B>
A fold starts at a "{{{" marker. The following number specifies the fold
level. What happens depends on the difference between the current fold level
and the level 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 <A HREF="#folds">folds</A> 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 <A HREF="various.html#less">less</A>
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:
<B> {{{1</B>
<B> fold level here is 1</B>
<B> {{{3</B>
<B> fold level here is 3</B>
<B> }}}3</B>
<B> fold level here is 2</B>
You can also use matching pairs of "{{{" and "}}}" markers to define <A HREF="#folds">folds</A>.
Each "{{{" increases the fold level by one, each "}}}" decreases the fold
level by one. Be careful to keep the markers matching! Example:
<B> {{{</B>
<B> fold level here is 1</B>
<B> {{{</B>
<B> fold level here is 2</B>
<B> }}}</B>
<B> fold level here is 1</B>
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 <A HREF="#folds">folds</A>, and unnumbered markers
locally in a function. For example use level one <A HREF="#folds">folds</A> for the sections of
your file like "structure definitions", "local variables" and "<A HREF="eval.html#functions">functions</A>".
Use level 2 markers for each definition and function, Use unnumbered markers
inside <A HREF="eval.html#functions">functions</A>. When you make changes in a function to split up <A HREF="#folds">folds</A>, you
don't have to renumber the markers.
The markers can be set with the <A HREF="options.html#'foldmarker'">'foldmarker'</A> option. It is recommended to
keep this at the default value of "{{{,}}}", so that files can be exchanged
between Vim users. Only change <A HREF="motion.html#it">it</A> when <A HREF="motion.html#it">it</A> is required for the file (e.g., <A HREF="motion.html#it">it</A>
contains markers from another <A HREF="#folding">folding</A> editor, or the default markers cause
trouble for the language of the file).
*<A NAME="fold-create-marker"></A><B>fold-create-marker</B>*
"<A HREF="#zf">zf</A>" 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, <A HREF="motion.html#as">as</A> specified with
<A HREF="options.html#'foldmarker'">'foldmarker'</A>. The markers are appended to the end of the line.
<A HREF="options.html#'commentstring'">'commentstring'</A> is used if <A HREF="motion.html#it">it</A> 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 <A HREF="diff.html#do">do</A>.
- Folds nearby use a level number in their marker which gets in the way.
- The line is inside a comment, <A HREF="options.html#'commentstring'">'commentstring'</A> 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.
*<A NAME="fold-delete-marker"></A><B>fold-delete-marker</B>*
"<A HREF="#zd">zd</A>" 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, <A HREF="motion.html#as">as</A> specified
with <A HREF="options.html#'foldmarker'">'foldmarker'</A>, at the start and end of the fold. When the text around the
marker matches with <A HREF="options.html#'commentstring'">'commentstring'</A>, that text is deleted <A HREF="motion.html#as">as</A> 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 <A HREF="change.html#deleting">deleting</A> the fold.
- The marker contains a level number and is used to start or end several <A HREF="#folds">folds</A>
at the same time.
==============================================================================
2. Fold commands *<A NAME="fold-commands"></A><B>fold-commands</B>* *<A NAME="E490"></A><B>E490</B>*
All <A HREF="#folding">folding</A> commands start with "<A HREF="index.html#z">z</A>". Hint: the "<A HREF="index.html#z">z</A>" looks like a folded piece
of paper, if you look at <A HREF="motion.html#it">it</A> from the side.
<B><FONT COLOR="PURPLE">CREATING AND DELETING FOLDS </FONT></B>
*<A NAME="zf"></A><B>zf</B>* *<A NAME="E350"></A><B>E350</B>*
zf{motion} or
{Visual}zf Operator to create a fold.
This only works when <A HREF="options.html#'foldmethod'">'foldmethod'</A> is "manual" or "marker".
The new fold will be closed for the "manual" method.
<A HREF="options.html#'foldenable'">'foldenable'</A> will be set.
Also see |<A HREF="#fold-create-marker">fold-create-marker</A>|.
*<A NAME="zF"></A><B>zF</B>*
<A HREF="#zF">zF</A> Create a fold for <A HREF="intro.html#[count]">[count]</A> lines. Works like "<A HREF="#zf">zf</A>".
:{range}fo[ld] *<A NAME=":fold"></A><B>:fold</B>* *<A NAME=":fo"></A><B>:fo</B>*
Create a fold for the lines in {range}. Works like "<A HREF="#zf">zf</A>".
*<A NAME="zd"></A><B>zd</B>* *<A NAME="E351"></A><B>E351</B>*
<A HREF="#zd">zd</A> Delete one fold at the cursor. When the cursor is on a folded
line, that fold is deleted. Nested <A HREF="#folds">folds</A> are moved one level
up. In <A HREF="visual.html#Visual">Visual</A> mode one level of all <A HREF="#folds">folds</A> (partially) in the
selected area are deleted.
Careful: This easily deletes more <A HREF="#folds">folds</A> than you expect and
there is no <A HREF="undo.html#undo">undo</A> for manual <A HREF="#folding">folding</A>.
This only works when <A HREF="options.html#'foldmethod'">'foldmethod'</A> is "manual" or "marker".
Also see |<A HREF="#fold-delete-marker">fold-delete-marker</A>|.
*<A NAME="zD"></A><B>zD</B>*
<A HREF="#zD">zD</A> Delete <A HREF="#folds">folds</A> recursively at the cursor. In <A HREF="visual.html#Visual">Visual</A> mode all
<A HREF="#folds">folds</A> (partially) in the selected area and all nested <A HREF="#folds">folds</A> in
them are deleted.
This only works when <A HREF="options.html#'foldmethod'">'foldmethod'</A> is "manual" or "marker".
Also see |<A HREF="#fold-delete-marker">fold-delete-marker</A>|.
*<A NAME="zE"></A><B>zE</B>* *<A NAME="E352"></A><B>E352</B>*
<A HREF="#zE">zE</A> Eliminate all <A HREF="#folds">folds</A> in the <A HREF="windows.html#window">window</A>.
This only works when <A HREF="options.html#'foldmethod'">'foldmethod'</A> is "manual" or "marker".
Also see |<A HREF="#fold-delete-marker">fold-delete-marker</A>|.
<B><FONT COLOR="PURPLE">OPENING AND CLOSING FOLDS </FONT></B>
A fold smaller than <A HREF="options.html#'foldminlines'">'foldminlines'</A> will always be displayed like <A HREF="motion.html#it">it</A> was open.
Therefore the commands below may work differently on small <A HREF="#folds">folds</A>.
*<A NAME="zo"></A><B>zo</B>*
<A HREF="#zo">zo</A> Open one fold under the cursor. When a <A HREF="intro.html#count">count</A> is given, that
many <A HREF="#folds">folds</A> deep will be opened. In <A HREF="visual.html#Visual">Visual</A> mode one level of
<A HREF="#folds">folds</A> is opened for all lines in the selected area.
*<A NAME="zO"></A><B>zO</B>*
<A HREF="#zO">zO</A> Open all <A HREF="#folds">folds</A> under the cursor recursively. Folds that don't
contain the cursor line are unchanged.
In <A HREF="visual.html#Visual">Visual</A> mode <A HREF="motion.html#it">it</A> opens all <A HREF="#folds">folds</A> that are in the selected
area, also those that are only partly selected.
*<A NAME="zc"></A><B>zc</B>*
<A HREF="#zc">zc</A> Close one fold under the cursor. When a <A HREF="intro.html#count">count</A> is given, that
many <A HREF="#folds">folds</A> deep are closed. In <A HREF="visual.html#Visual">Visual</A> mode one level of <A HREF="#folds">folds</A>
is closed for all lines in the selected area.
<A HREF="options.html#'foldenable'">'foldenable'</A> will be set.
*<A NAME="zC"></A><B>zC</B>*
<A HREF="#zC">zC</A> Close all <A HREF="#folds">folds</A> under the cursor recursively. Folds that
don't contain the cursor line are unchanged.
In <A HREF="visual.html#Visual">Visual</A> mode <A HREF="motion.html#it">it</A> closes all <A HREF="#folds">folds</A> that are in the selected
area, also those that are only partly selected.
<A HREF="options.html#'foldenable'">'foldenable'</A> will be set.
*<A NAME="za"></A><B>za</B>*
<A HREF="#za">za</A> When on a closed fold: open <A HREF="motion.html#it">it</A>. When <A HREF="#folds">folds</A> are nested, you
may have to use "<A HREF="#za">za</A>" several times. When a <A HREF="intro.html#count">count</A> is given,
that many closed <A HREF="#folds">folds</A> are opened.
When on an open fold: close <A HREF="motion.html#it">it</A> and set <A HREF="options.html#'foldenable'">'foldenable'</A>. This
will only close one level, since using "<A HREF="#za">za</A>" again will open
the fold. When a <A HREF="intro.html#count">count</A> is given that many <A HREF="#folds">folds</A> will be
closed (that's not the same <A HREF="motion.html#as">as</A> <A HREF="repeat.html#repeating">repeating</A> "<A HREF="#za">za</A>" that many
times).
*<A NAME="zA"></A><B>zA</B>*
<A HREF="#zA">zA</A> When on a closed fold: open <A HREF="motion.html#it">it</A> recursively.
When on an open fold: close <A HREF="motion.html#it">it</A> recursively and set
<A HREF="options.html#'foldenable'">'foldenable'</A>.
*<A NAME="zv"></A><B>zv</B>*
<A HREF="#zv">zv</A> <A HREF="starting.html#View">View</A> cursor line: Open just enough <A HREF="#folds">folds</A> to make the line in
which the cursor is located not folded.
*<A NAME="zx"></A><B>zx</B>*
<A HREF="#zx">zx</A> Update <A HREF="#folds">folds</A>: Undo manually opened and closed <A HREF="#folds">folds</A>: re-apply
<A HREF="options.html#'foldlevel'">'foldlevel'</A>, then <A HREF="diff.html#do">do</A> "<A HREF="#zv">zv</A>": <A HREF="starting.html#View">View</A> cursor line.
Also forces recomputing <A HREF="#folds">folds</A>. This is useful when using
<A HREF="options.html#'foldexpr'">'foldexpr'</A> and the buffer is changed in a way that results in
<A HREF="#folds">folds</A> not to be updated properly.
*<A NAME="zX"></A><B>zX</B>*
<A HREF="#zX">zX</A> Undo manually opened and closed <A HREF="#folds">folds</A>: re-apply <A HREF="options.html#'foldlevel'">'foldlevel'</A>.
Also forces recomputing <A HREF="#folds">folds</A>, like |<A HREF="#zx">zx</A>|.
*<A NAME="zm"></A><B>zm</B>*
<A HREF="#zm">zm</A> Fold more: Subtract |<A HREF="eval.html#v:count1">v:count1</A>| from <A HREF="options.html#'foldlevel'">'foldlevel'</A>. If <A HREF="options.html#'foldlevel'">'foldlevel'</A> was
already zero nothing happens.
<A HREF="options.html#'foldenable'">'foldenable'</A> will be set.
*<A NAME="zM"></A><B>zM</B>*
<A HREF="#zM">zM</A> Close all <A HREF="#folds">folds</A>: set <A HREF="options.html#'foldlevel'">'foldlevel'</A> to 0.
<A HREF="options.html#'foldenable'">'foldenable'</A> will be set.
*<A NAME="zr"></A><B>zr</B>*
<A HREF="#zr">zr</A> Reduce <A HREF="#folding">folding</A>: Add |<A HREF="eval.html#v:count1">v:count1</A>| to <A HREF="options.html#'foldlevel'">'foldlevel'</A>.
*<A NAME="zR"></A><B>zR</B>*
<A HREF="#zR">zR</A> Open all <A HREF="#folds">folds</A>. This sets <A HREF="options.html#'foldlevel'">'foldlevel'</A> to highest fold level.
*<A NAME=":foldo"></A><B>:foldo</B>* *<A NAME=":foldopen"></A><B>:foldopen</B>*
:{range}foldo[pen][!]
Open <A HREF="#folds">folds</A> in {range}. When [!] is added all <A HREF="#folds">folds</A> are
opened. Useful to see all the text in {range}. Without [!]
one level of <A HREF="#folds">folds</A> is opened.
*<A NAME=":foldc"></A><B>:foldc</B>* *<A NAME=":foldclose"></A><B>:foldclose</B>*
:{range}foldc[lose][!]
Close <A HREF="#folds">folds</A> in {range}. When [!] is added all <A HREF="#folds">folds</A> are
closed. Useful to hide all the text in {range}. Without [!]
one level of <A HREF="#folds">folds</A> is closed.
*<A NAME="zn"></A><B>zn</B>*
<A HREF="#zn">zn</A> Fold none: reset <A HREF="options.html#'foldenable'">'foldenable'</A>. All <A HREF="#folds">folds</A> will be open.
*<A NAME="zN"></A><B>zN</B>*
<A HREF="#zN">zN</A> Fold normal: set <A HREF="options.html#'foldenable'">'foldenable'</A>. All <A HREF="#folds">folds</A> will be <A HREF="motion.html#as">as</A> they
were before.
*<A NAME="zi"></A><B>zi</B>*
<A HREF="#zi">zi</A> Invert <A HREF="options.html#'foldenable'">'foldenable'</A>.
<B><FONT COLOR="PURPLE">MOVING OVER FOLDS </FONT></B>
*<A NAME="[z"></A><B>[z</B>*
<A HREF="#[z">[z</A> Move to the start of the current open fold. If already at the
start, move to the start of the fold that contains <A HREF="motion.html#it">it</A>. If
there is no containing fold, the command fails.
When a <A HREF="intro.html#count">count</A> is used, repeats the command <A HREF="intro.html#[count]">[count]</A> times.
*<A NAME="]z"></A><B>]z</B>*
<A HREF="#]z">]z</A> Move to the end of the current open fold. If already at the
end, move to the end of the fold that contains <A HREF="motion.html#it">it</A>. If there
is no containing fold, the command fails.
When a <A HREF="intro.html#count">count</A> is used, repeats the command <A HREF="intro.html#[count]">[count]</A> times.
*<A NAME="zj"></A><B>zj</B>*
<A HREF="#zj">zj</A> Move downwards to the start of the next fold. A closed fold
is counted <A HREF="motion.html#as">as</A> one fold.
When a <A HREF="intro.html#count">count</A> is used, repeats the command <A HREF="intro.html#[count]">[count]</A> times.
This command can be used after an |<A HREF="motion.html#operator">operator</A>|.
*<A NAME="zk"></A><B>zk</B>*
<A HREF="#zk">zk</A> Move upwards to the end of the previous fold. A closed fold
is counted <A HREF="motion.html#as">as</A> one fold.
When a <A HREF="intro.html#count">count</A> is used, repeats the command <A HREF="intro.html#[count]">[count]</A> times.
This command can be used after an |<A HREF="motion.html#operator">operator</A>|.
<B><FONT COLOR="PURPLE">EXECUTING COMMANDS ON FOLDS </FONT></B>
:[range]foldd[oopen] {cmd} *<A NAME=":foldd"></A><B>:foldd</B>* *<A NAME=":folddoopen"></A><B>:folddoopen</B>*
Execute {cmd} on all lines that are not in a closed fold.
When <A HREF="cmdline.html#[range]">[range]</A> is given, only these lines are used.
Each time {cmd} is executed the cursor is positioned on the
line <A HREF="motion.html#it">it</A> is executed for.
This works like the "<A HREF="repeat.html#:global">:global</A>" command: First all lines that
are not in a closed fold are marked. Then the {cmd} is
executed for all marked lines. Thus when {cmd} changes the
<A HREF="#folds">folds</A>, this has no influence on where <A HREF="motion.html#it">it</A> is executed (except
when lines are deleted, of course).
Example:
<B> :folddoopen s/end/loop_end/ge</B>
Note the use of the "<A HREF="motion.html#e">e</A>" flag to avoid getting an error message
where "end" doesn't match.
:[range]folddoc[losed] {cmd} *<A NAME=":folddoc"></A><B>:folddoc</B>* *<A NAME=":folddoclosed"></A><B>:folddoclosed</B>*
Execute {cmd} on all lines that are in a closed fold.
Otherwise like "<A HREF="#:folddoopen">:folddoopen</A>".
==============================================================================
3. Fold <A HREF="options.html#options">options</A> *<A NAME="fold-options"></A><B>fold-options</B>*
COLORS *<A NAME="fold-colors"></A><B>fold-colors</B>*
The colors of a closed fold are set with the Folded group |<A HREF="syntax.html#hl-Folded">hl-Folded</A>|. The
colors of the fold column are set with the FoldColumn group |<A HREF="syntax.html#hl-FoldColumn">hl-FoldColumn</A>|.
Example to set the colors:
<B> :highlight Folded guibg=grey guifg=blue</B>
<B> :highlight FoldColumn guibg=darkgrey guifg=white</B>
FOLDLEVEL *<A NAME="fold-foldlevel"></A><B>fold-foldlevel</B>*
<A HREF="options.html#'foldlevel'">'foldlevel'</A> is a number option: The higher the more folded regions are open.
When <A HREF="options.html#'foldlevel'">'foldlevel'</A> is 0, all <A HREF="#folds">folds</A> are closed.
When <A HREF="options.html#'foldlevel'">'foldlevel'</A> is positive, some <A HREF="#folds">folds</A> are closed.
When <A HREF="options.html#'foldlevel'">'foldlevel'</A> is very high, all <A HREF="#folds">folds</A> are open.
<A HREF="options.html#'foldlevel'">'foldlevel'</A> is applied when <A HREF="motion.html#it">it</A> is changed. After that manually <A HREF="#folds">folds</A> can be
opened and closed.
When increased, <A HREF="#folds">folds</A> above the new level are opened. No manually opened
<A HREF="#folds">folds</A> will be closed.
When decreased, <A HREF="#folds">folds</A> above the new level are closed. No manually closed
<A HREF="#folds">folds</A> will be opened.
FOLDTEXT *<A NAME="fold-foldtext"></A><B>fold-foldtext</B>*
<A HREF="options.html#'foldtext'">'foldtext'</A> is a <A HREF="eval.html#string">string</A> option that specifies an <A HREF="eval.html#expression">expression</A>. This <A HREF="eval.html#expression">expression</A>
is evaluated to obtain the text displayed for a closed fold. Example:
<B> :set foldtext=v:folddashes.substitute(getline(v:foldstart),'/\\*\\\|\\*/\\\|{{{\\d\\=','','g')</B>
This shows the first line of the fold, with "/*", "*/" and "{{{" removed.
Note the use of backslashes to avoid some characters to be interpreted by the
"<A HREF="options.html#:set">:set</A>" command. It's simpler to define a function and call that:
<B> :set foldtext=MyFoldText()</B>
<B> :function MyFoldText()</B>
<B> : let line = getline(v:foldstart)</B>
<B> : let sub = substitute(line, '/\*\|\*/\|{{{\d\=', '', 'g')</B>
<B> : return v:folddashes . sub</B>
<B> :endfunction</B>
Evaluating <A HREF="options.html#'foldtext'">'foldtext'</A> is done in the |<A HREF="eval.html#sandbox">sandbox</A>|. The current <A HREF="windows.html#window">window</A> is set to
the <A HREF="windows.html#window">window</A> that displays the line. Errors are ignored.
The default value is |<A HREF="eval.html#foldtext()">foldtext()</A>|. This returns a reasonable text for most
types of <A HREF="#folding">folding</A>. If you don't like <A HREF="motion.html#it">it</A>, you can specify your own <A HREF="options.html#'foldtext'">'foldtext'</A>
<A HREF="eval.html#expression">expression</A>. It can use these special Vim <A HREF="eval.html#variables">variables</A>:
<A HREF="eval.html#v:foldstart">v:foldstart</A> line number of first line in the fold
<A HREF="eval.html#v:foldend">v:foldend</A> line number of last line in the fold
<A HREF="eval.html#v:folddashes">v:folddashes</A> a <A HREF="eval.html#string">string</A> that contains dashes to represent the
foldlevel.
<A HREF="eval.html#v:foldlevel">v:foldlevel</A> the foldlevel of the fold
In the result a TAB is replaced with a space and unprintable characters are
made into printable characters.
The resulting line is truncated to fit in the <A HREF="windows.html#window">window</A>, <A HREF="motion.html#it">it</A> never wraps.
When there is room after the text, <A HREF="motion.html#it">it</A> is filled with the character specified
by <A HREF="options.html#'fillchars'">'fillchars'</A>.
Note that backslashes need to be used for characters that the "<A HREF="options.html#:set">:set</A>" command
handles differently: Space, backslash and double-quote. |<A HREF="options.html#option-backslash">option-backslash</A>|
FOLDCOLUMN *<A NAME="fold-foldcolumn"></A><B>fold-foldcolumn</B>*
<A HREF="options.html#'foldcolumn'">'foldcolumn'</A> is a number, which sets the width for a column on the side of the
<A HREF="windows.html#window">window</A> to indicate <A HREF="#folds">folds</A>. When <A HREF="motion.html#it">it</A> is zero, there is no foldcolumn. A normal
value is 4 or 5. The minimal useful value is 2, although 1 still provides
some information. The maximum is 12.
An open fold is indicated with a column that has a '<A HREF="motion.html#-">-</A>' at the top and '|'
characters below <A HREF="motion.html#it">it</A>. This column stops where the open fold stops. When <A HREF="#folds">folds</A>
nest, the nested fold is one character right of the fold it's contained in.
A closed fold is indicated with a '<A HREF="motion.html#+">+</A>'.
Where the fold column is too narrow to display all nested <A HREF="#folds">folds</A>, digits are
shown to indicate the nesting level.
The mouse can also be used to open and close <A HREF="#folds">folds</A> by clicking in the
fold column:
- Click on a '<A HREF="motion.html#+">+</A>' to open the closed fold at this row.
- Click on any other non-blank character to close the open fold at this row.
OTHER OPTIONS
<A HREF="options.html#'foldenable'">'foldenable'</A> <A HREF="options.html#'fen'">'fen'</A>: Open all <A HREF="#folds">folds</A> while not set.
<A HREF="options.html#'foldexpr'">'foldexpr'</A> <A HREF="options.html#'fde'">'fde'</A>: Expression used for "<A HREF="eval.html#expr">expr</A>" <A HREF="#folding">folding</A>.
<A HREF="options.html#'foldignore'">'foldignore'</A> <A HREF="options.html#'fdi'">'fdi'</A>: Characters used for "indent" <A HREF="#folding">folding</A>.
<A HREF="options.html#'foldmarker'">'foldmarker'</A> <A HREF="options.html#'fmr'">'fmr'</A>: Defined markers used for "marker" <A HREF="#folding">folding</A>.
<A HREF="options.html#'foldmethod'">'foldmethod'</A> <A HREF="options.html#'fdm'">'fdm'</A>: Name of the current <A HREF="#folding">folding</A> method.
<A HREF="options.html#'foldminlines'">'foldminlines'</A> <A HREF="options.html#'fml'">'fml'</A>: Minimum number of screen lines for a fold to be
displayed closed.
<A HREF="options.html#'foldnestmax'">'foldnestmax'</A> <A HREF="options.html#'fdn'">'fdn'</A>: Maximum nesting for "indent" and "<A HREF="syntax.html#syntax">syntax</A>" <A HREF="#folding">folding</A>.
<A HREF="options.html#'foldopen'">'foldopen'</A> <A HREF="options.html#'fdo'">'fdo'</A>: Which kinds of commands open closed <A HREF="#folds">folds</A>.
<A HREF="options.html#'foldclose'">'foldclose'</A> <A HREF="options.html#'fcl'">'fcl'</A>: When the <A HREF="#folds">folds</A> not under the cursor are closed.
==============================================================================
4. Behavior of <A HREF="#folds">folds</A> *<A NAME="fold-behavior"></A><B>fold-behavior</B>*
When moving the cursor upwards or downwards and when <A HREF="scroll.html#scrolling">scrolling</A>, the cursor
will move to the first line of a sequence of folded lines. When the cursor is
already on a folded line, <A HREF="motion.html#it">it</A> moves to the next unfolded line or the next
closed fold.
While the cursor is on folded lines, the cursor is always displayed in the
first column. The ruler does show the actual cursor position, but since the
line is folded, <A HREF="motion.html#it">it</A> cannot be displayed there.
Many <A HREF="intro.html#movement">movement</A> commands handle a sequence of folded lines like an empty line.
For example, the "<A HREF="motion.html#w">w</A>" command stops once in the first column.
When in <A HREF="insert.html#Insert">Insert</A> mode, the cursor line is never folded. That allows you to see
what you type!
When using an <A HREF="motion.html#operator">operator</A>, a closed fold is included <A HREF="motion.html#as">as</A> a whole. Thus "<A HREF="change.html#dl">dl</A>"
deletes the whole closed fold under the cursor.
For <A HREF="intro.html#Ex">Ex</A> commands that work on buffer lines the range is adjusted to always
start at the first line of a closed fold and end at the last line of a closed
fold. Thus this command:
<B> :s/foo/bar/g</B>
when used with the cursor on a closed fold, will replace "foo" with "<A HREF="motion.html#bar">bar</A>" in
all lines of the fold.
This does not happen for |<A HREF="#:folddoopen">:folddoopen</A>| and |<A HREF="#:folddoclosed">:folddoclosed</A>|.
When editing a buffer that has been edited before, the last used <A HREF="#folding">folding</A>
settings are used again. For manual <A HREF="#folding">folding</A> the defined <A HREF="#folds">folds</A> are restored.
For all <A HREF="#folding">folding</A> methods the manually opened and closed <A HREF="#folds">folds</A> are restored.
If this buffer has been edited in this <A HREF="windows.html#window">window</A>, the values from back then are
used. Otherwise the values from the <A HREF="windows.html#window">window</A> where the buffer was edited last
are used.
==============================================================================
<A HREF="#top">top</A> - <A HREF="index.html">main help file</A>
</PRE>
</BODY>
</HTML>
|