代码拉取完成,页面将自动刷新
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>fold - Vim Documentation</title>
<meta name="Generator" content="Vim/8.0">
<meta name="plugin-version" content="vim8.0">
<meta name="syntax" content="help">
<meta name="settings" content="no_pre,use_css,expand_tabs">
<link rel="stylesheet" href="style.css" type="text/css" />
<script src="jquery.min.js" type="text/javascript"></script>
<script src="mark-current-page.js" type="text/javascript"></script>
</head>
<body>
<header>
<div class="header">
<a href="http://vim-jp.org/">vim-jp</a>
/ <a href="http://vim-jp.org/vimdoc-en/">vimdoc-en</a>
/ fold<br />
<a name="top"></a><h1>fold - Vim Documentation</h1>
<a href="index.html">Return to main</a>
<span class="EnglishJapaneseLink">
<span class="CurrentLanguage">English</span>
</span>
</div>
</header>
<nav>
<dl>
<dt>BASIC</dt>
<dd><ul>
<li><a href="quickref.html">quickref</a></li>
<li><a href="sponsor.html">sponsor</a></li>
</ul></dd>
<dt>USER MANUAL</dt>
<dd><ul>
<li><a href="usr_toc.html">usr_toc</a></li>
</ul></dd>
<dt>Getting Started</dt>
<dd><ul>
<li><a href="usr_01.html">usr_01</a></li>
<li><a href="usr_02.html">usr_02</a></li>
<li><a href="usr_03.html">usr_03</a></li>
<li><a href="usr_04.html">usr_04</a></li>
<li><a href="usr_05.html">usr_05</a></li>
<li><a href="usr_06.html">usr_06</a></li>
<li><a href="usr_07.html">usr_07</a></li>
<li><a href="usr_08.html">usr_08</a></li>
<li><a href="usr_09.html">usr_09</a></li>
<li><a href="usr_10.html">usr_10</a></li>
<li><a href="usr_11.html">usr_11</a></li>
<li><a href="usr_12.html">usr_12</a></li>
</ul></dd>
<dt>Editing Effectively</dt>
<dd><ul>
<li><a href="usr_20.html">usr_20</a></li>
<li><a href="usr_21.html">usr_21</a></li>
<li><a href="usr_22.html">usr_22</a></li>
<li><a href="usr_23.html">usr_23</a></li>
<li><a href="usr_24.html">usr_24</a></li>
<li><a href="usr_25.html">usr_25</a></li>
<li><a href="usr_26.html">usr_26</a></li>
<li><a href="usr_27.html">usr_27</a></li>
<li><a href="usr_28.html">usr_28</a></li>
<li><a href="usr_29.html">usr_29</a></li>
<li><a href="usr_30.html">usr_30</a></li>
<li><a href="usr_31.html">usr_31</a></li>
<li><a href="usr_32.html">usr_32</a></li>
</ul></dd>
<dt>Tuning Vim</dt>
<dd><ul>
<li><a href="usr_40.html">usr_40</a></li>
<li><a href="usr_41.html">usr_41</a></li>
<li><a href="usr_42.html">usr_42</a></li>
<li><a href="usr_43.html">usr_43</a></li>
<li><a href="usr_44.html">usr_44</a></li>
<li><a href="usr_45.html">usr_45</a></li>
</ul></dd>
<dt>Making Vim Run</dt>
<dd><ul>
<li><a href="usr_90.html">usr_90</a></li>
</ul></dd>
<dt>General subjects</dt>
<dd><ul>
<li><a href="intro.html">intro</a></li>
<li><a href="index.html">help</a></li>
<li><a href="helphelp.html">helphelp</a></li>
<li><a href="vimindex.html">index</a></li>
<li><a href="tags.html">tags</a></li>
<li><a href="howto.html">howto</a></li>
<li><a href="tips.html">tips</a></li>
<li><a href="message.html">message</a></li>
<li><a href="quotes.html">quotes</a></li>
<li><a href="todo.html">todo</a></li>
<li><a href="debug.html">debug</a></li>
<li><a href="develop.html">develop</a></li>
<li><a href="uganda.html">uganda</a></li>
</ul></dd>
<dt>Basic editing</dt>
<dd><ul>
<li><a href="starting.html">starting</a></li>
<li><a href="editing.html">editing</a></li>
<li><a href="motion.html">motion</a></li>
<li><a href="scroll.html">scroll</a></li>
<li><a href="insert.html">insert</a></li>
<li><a href="change.html">change</a></li>
<li><a href="indent.html">indent</a></li>
<li><a href="undo.html">undo</a></li>
<li><a href="repeat.html">repeat</a></li>
<li><a href="visual.html">visual</a></li>
<li><a href="various.html">various</a></li>
<li><a href="recover.html">recover</a></li>
</ul></dd>
<dt>Advanced editing</dt>
<dd><ul>
<li><a href="cmdline.html">cmdline</a></li>
<li><a href="options.html">options</a></li>
<li><a href="pattern.html">pattern</a></li>
<li><a href="map.html">map</a></li>
<li><a href="tagsrch.html">tagsrch</a></li>
<li><a href="quickfix.html">quickfix</a></li>
<li><a href="windows.html">windows</a></li>
<li><a href="tabpage.html">tabpage</a></li>
<li><a href="syntax.html">syntax</a></li>
<li><a href="spell.html">spell</a></li>
<li><a href="diff.html">diff</a></li>
<li><a href="autocmd.html">autocmd</a></li>
<li><a href="filetype.html">filetype</a></li>
<li><a href="eval.html">eval</a></li>
<li><a href="channel.html">channel</a></li>
<li><a href="fold.html">fold</a></li>
</ul></dd>
<dt>Special issues</dt>
<dd><ul>
<li><a href="print.html">print</a></li>
<li><a href="remote.html">remote</a></li>
<li><a href="term.html">term</a></li>
<li><a href="digraph.html">digraph</a></li>
<li><a href="mbyte.html">mbyte</a></li>
<li><a href="mlang.html">mlang</a></li>
<li><a href="arabic.html">arabic</a></li>
<li><a href="farsi.html">farsi</a></li>
<li><a href="hebrew.html">hebrew</a></li>
<li><a href="russian.html">russian</a></li>
<li><a href="ft_ada.html">ft_ada</a></li>
<li><a href="ft_sql.html">ft_sql</a></li>
<li><a href="hangulin.html">hangulin</a></li>
<li><a href="rileft.html">rileft</a></li>
</ul></dd>
<dt>GUI</dt>
<dd><ul>
<li><a href="gui.html">gui</a></li>
<li><a href="gui_w32.html">gui_w32</a></li>
<li><a href="gui_x11.html">gui_x11</a></li>
</ul></dd>
<dt>Interfaces</dt>
<dd><ul>
<li><a href="if_cscop.html">if_cscop</a></li>
<li><a href="if_lua.html">if_lua</a></li>
<li><a href="if_mzsch.html">if_mzsch</a></li>
<li><a href="if_perl.html">if_perl</a></li>
<li><a href="if_pyth.html">if_pyth</a></li>
<li><a href="if_tcl.html">if_tcl</a></li>
<li><a href="if_ole.html">if_ole</a></li>
<li><a href="if_ruby.html">if_ruby</a></li>
<li><a href="debugger.html">debugger</a></li>
<li><a href="workshop.html">workshop</a></li>
<li><a href="netbeans.html">netbeans</a></li>
<li><a href="sign.html">sign</a></li>
</ul></dd>
<dt>Versions</dt>
<dd><ul>
<li><a href="vi_diff.html">vi_diff</a></li>
<li><a href="version4.html">version4</a></li>
<li><a href="version5.html">version5</a></li>
<li><a href="version6.html">version6</a></li>
<li><a href="version7.html">version7</a></li>
<li><a href="version8.html">version8</a></li>
</ul></dd>
<dt>Remarks about specific systems</dt>
<dd><ul>
<li><a href="os_390.html">os_390</a></li>
<li><a href="os_amiga.html">os_amiga</a></li>
<li><a href="os_beos.html">os_beos</a></li>
<li><a href="os_dos.html">os_dos</a></li>
<li><a href="os_mac.html">os_mac</a></li>
<li><a href="os_mint.html">os_mint</a></li>
<li><a href="os_msdos.html">os_msdos</a></li>
<li><a href="os_os2.html">os_os2</a></li>
<li><a href="os_qnx.html">os_qnx</a></li>
<li><a href="os_risc.html">os_risc</a></li>
<li><a href="os_unix.html">os_unix</a></li>
<li><a href="os_vms.html">os_vms</a></li>
<li><a href="os_win32.html">os_win32</a></li>
</ul></dd>
<dt>Standard plugins</dt>
<dd><ul>
<li><a href="pi_getscript.html">pi_getscript</a></li>
<li><a href="pi_gzip.html">pi_gzip</a></li>
<li><a href="pi_logipat.html">pi_logipat</a></li>
<li><a href="pi_netrw.html">pi_netrw</a></li>
<li><a href="pi_paren.html">pi_paren</a></li>
<li><a href="pi_tar.html">pi_tar</a></li>
<li><a href="pi_vimball.html">pi_vimball</a></li>
<li><a href="pi_zip.html">pi_zip</a></li>
</ul></dd>
<dt>Filetype plugins</dt>
<dd><ul>
<li><a href="pi_spec.html">pi_spec</a></li>
</ul></dd>
<dt>Others</dt>
<dd><ul>
<li><a href="vim_faq.html">vim_faq</a></li>
</ul></dd>
</dl>
</nav>
<article class="Vimdoc VimdocJa">
<div id='vimCodeElement'>
<a class="Constant" href="fold.html" name="fold.txt">fold.txt</a> For <span class="Identifier">Vim version 8.0.</span> Last change: 2017 Mar 18<br>
<br>
<br>
<span class="Identifier">VIM REFERENCE MANUAL by Bram Moolenaar</span><br>
<br>
<br>
Folding <a class="Constant" href="fold.html#Folding" name="Folding">Folding</a> <a class="Constant" href="fold.html#folding" name="folding">folding</a> <a class="Constant" href="fold.html#folds" name="folds">folds</a><br>
<br>
You can find an introduction on folding in chapter 28 of the user manual.<br>
<a class="Identifier" href="usr_28.html">usr_28.txt</a><br>
<br>
1. Fold methods <a class="Identifier" href="fold.html#fold-methods">fold-methods</a><br>
2. Fold commands <a class="Identifier" href="fold.html#fold-commands">fold-commands</a><br>
3. Fold options <a class="Identifier" href="fold.html#fold-options">fold-options</a><br>
4. Behavior of folds <a class="Identifier" href="fold.html#fold-behavior">fold-behavior</a><br>
<br>
<span class="Special">{Vi has no Folding}</span><br>
<span class="Special">{not available when compiled without the </span><a class="Identifier" href="various.html#+folding">+folding</a><span class="Special"> feature}</span><br>
<br>
<span class="PreProc">==============================================================================</span><br>
1. Fold methods <a class="Constant" href="fold.html#fold-methods" name="fold-methods">fold-methods</a><br>
<br>
The folding method can be set with the <a class="Type" href="options.html#'foldmethod'">'foldmethod'</a> option.<br>
<br>
When setting <a class="Type" href="options.html#'foldmethod'">'foldmethod'</a> to a value other than "manual", all folds are<br>
deleted and new ones created. Switching to the "manual" method doesn't remove<br>
the existing folds. This can be used to first define the folds automatically<br>
and then change them manually.<br>
<br>
There are six methods to select folds:<br>
manual manually define folds<br>
indent more indent means a higher fold level<br>
expr specify an expression to define folds<br>
syntax folds defined by syntax highlighting<br>
diff folds for unchanged text<br>
marker folds defined by markers in the text<br>
<br>
<br>
<span class="Statement">MANUAL </span><a class="Constant" href="fold.html#fold-manual" name="fold-manual">fold-manual</a><br>
<br>
Use commands to manually define the fold regions. This can also be used by a<br>
script that parses text to find folds.<br>
<br>
The level of a fold is only defined by its nesting. To increase the fold<br>
level of a fold for a range of lines, define a fold inside it that has the<br>
same lines.<br>
<br>
The manual folds are lost when you abandon the file. To save the folds use<br>
the <a class="Identifier" href="starting.html#:mkview">:mkview</a> command. The view can be restored later with <a class="Identifier" href="starting.html#:loadview">:loadview</a>.<br>
<br>
<br>
<span class="Statement">INDENT </span><a class="Constant" href="fold.html#fold-indent" name="fold-indent">fold-indent</a><br>
<br>
The folds are automatically defined by the indent of the lines.<br>
<br>
The foldlevel is computed from the indent of the line, divided by the<br>
<a class="Type" href="options.html#'shiftwidth'">'shiftwidth'</a> (rounded down). A sequence of lines with the same or higher fold<br>
level form a fold, with the lines with a higher level forming a nested fold.<br>
<br>
The nesting of folds is limited with <a class="Type" href="options.html#'foldnestmax'">'foldnestmax'</a>.<br>
<br>
Some lines are ignored and get the fold level of the line above or below it,<br>
whichever is lower. These are empty or white lines and lines starting<br>
with a character in <a class="Type" href="options.html#'foldignore'">'foldignore'</a>. White space is skipped before checking for<br>
characters in <a class="Type" href="options.html#'foldignore'">'foldignore'</a>. For C use "#" to ignore preprocessor lines.<br>
<br>
When you want to ignore lines in another way, use the "expr" method. The<br>
<a class="Identifier" href="eval.html#indent()">indent()</a> function can be used in <a class="Type" href="options.html#'foldexpr'">'foldexpr'</a> to get the indent of a line.<br>
<br>
<br>
<span class="Statement">EXPR </span><a class="Constant" href="fold.html#fold-expr" name="fold-expr">fold-expr</a><br>
<br>
The folds are automatically defined by their foldlevel, like with the "indent"<br>
method. The value of the <a class="Type" href="options.html#'foldexpr'">'foldexpr'</a> option is evaluated to get the foldlevel<br>
of a line. Examples:<br>
This will create a fold for all consecutive lines that start with a tab:<br>
<div class="helpExample"> :set foldexpr=getline(v:lnum)[0]==\"\\t\"</div>
This will call a function to compute the fold level:<br>
<div class="helpExample"> :set foldexpr=MyFoldLevel(v:lnum)</div>
This will make a fold out of paragraphs separated by blank lines:<br>
<div class="helpExample"> :set foldexpr=getline(v:lnum)=~'^\\s*$'&&getline(v:lnum+1)=~'\\S'?'<1':1</div>
This does the same:<br>
<div class="helpExample"> :set foldexpr=getline(v:lnum-1)=~'^\\s*$'&&getline(v:lnum)=~'\\S'?'>1':1</div>
<br>
<span class="Todo">Note</span> that backslashes must be used to escape characters that ":set" handles<br>
differently (space, backslash, double quote, etc., see <a class="Identifier" href="options.html#option-backslash">option-backslash</a>).<br>
<br>
These are the conditions with which the expression is evaluated:<br>
- The current buffer and window are set for the line.<br>
- The variable "v:lnum" is set to the line number.<br>
- The result is used for the fold level in this way:<br>
<span class="PreProc">value meaning</span><br>
0 the line is not in a fold<br>
1, 2, .. the line is in a fold with this level<br>
-1 the fold level is undefined, use the fold level of a<br>
line before or after this line, whichever is the<br>
lowest.<br>
"=" use fold level from the previous line<br>
"a1", "a2", .. add one, two, .. to the fold level of the previous<br>
line, use the result for the current line<br>
"s1", "s2", .. subtract one, two, .. from the fold level of the<br>
previous line, use the result for the next line<br>
"<1", "<2", .. a fold with this level ends at this line<br>
">1", ">2", .. a fold with this level starts at this line<br>
<br>
It is not required to mark the start (end) of a fold with ">1" ("<1"), a fold<br>
will also start (end) when the fold level is higher (lower) than the fold<br>
level of the previous line.<br>
<br>
There must be no side effects from the expression. The text in the buffer,<br>
cursor position, the search patterns, options etc. must not be changed.<br>
You can change and restore them if you are careful.<br>
<br>
If there is some error in the expression, or the resulting value isn't<br>
recognized, there is no error message and the fold level will be zero.<br>
For debugging the <a class="Type" href="options.html#'debug'">'debug'</a> option can be set to "msg", the error messages will<br>
be visible then.<br>
<br>
<span class="Todo">Note</span>: Since the expression has to be evaluated for every line, this fold<br>
method can be very slow!<br>
<br>
Try to avoid the "=", "a" and "s" return values, since Vim often has to search<br>
backwards for a line for which the fold level is defined. This can be slow.<br>
<br>
An example of using "a1" and "s1": For a multi-line C comment, a line<br>
containing "/*" would return "a1" to start a fold, and a line containing "*/"<br>
would return "s1" to end the fold after that line:<br>
<div class="helpExample"> if match(thisline, '/\*') >= 0<br>
return 'a1'<br>
elseif match(thisline, '\*/') >= 0<br>
return 's1'<br>
else<br>
return '='<br>
endif</div>
However, this won't work for single line comments, strings, etc.<br>
<br>
<a class="Identifier" href="eval.html#foldlevel()">foldlevel()</a> can be useful to compute a fold level relative to a previous<br>
fold level. But <span class="Todo">note</span> that foldlevel() may return -1 if the level is not known<br>
yet. And it returns the level at the start of the line, while a fold might<br>
end in that line.<br>
<br>
It may happen that folds are not updated properly. You can use <a class="Identifier" href="fold.html#zx">zx</a> or <a class="Identifier" href="fold.html#zX">zX</a><br>
to force updating folds.<br>
<br>
<br>
<span class="Statement">SYNTAX </span><a class="Constant" href="fold.html#fold-syntax" name="fold-syntax">fold-syntax</a><br>
<br>
A fold is defined by syntax items that have the "fold" argument. <a class="Identifier" href="syntax.html#:syn-fold">:syn-fold</a><br>
<br>
The fold level is defined by nesting folds. The nesting of folds is limited<br>
with <a class="Type" href="options.html#'foldnestmax'">'foldnestmax'</a>.<br>
<br>
Be careful to specify proper syntax syncing. If this is not done right, folds<br>
may differ from the displayed highlighting. This is especially relevant when<br>
using patterns that match more than one line. In case of doubt, try using<br>
brute-force syncing:<br>
<div class="helpExample"> :syn sync fromstart</div>
<br>
<br>
<span class="Statement">DIFF </span><a class="Constant" href="fold.html#fold-diff" name="fold-diff">fold-diff</a><br>
<br>
The folds are automatically defined for text that is not part of a change or<br>
close to a change.<br>
<br>
This method only works properly when the <a class="Type" href="options.html#'diff'">'diff'</a> option is set for the current<br>
window and changes are being displayed. Otherwise the whole buffer will be<br>
one big fold.<br>
<br>
The <a class="Type" href="options.html#'diffopt'">'diffopt'</a> option can be used to specify the context. That is, the number<br>
of lines between the fold and a change that are not included in the fold. For<br>
example, to use a context of 8 lines:<br>
<div class="helpExample"> :set diffopt=filler,context:8</div>
The default context is six lines.<br>
<br>
When <a class="Type" href="options.html#'scrollbind'">'scrollbind'</a> is also set, Vim will attempt to keep the same folds open in<br>
other diff windows, so that the same text is visible.<br>
<br>
<br>
<span class="Statement">MARKER </span><a class="Constant" href="fold.html#fold-marker" name="fold-marker">fold-marker</a><br>
<br>
Markers in the text tell where folds start and end. This allows you to<br>
precisely specify the folds. This will allow deleting and putting a fold,<br>
without the risk of including the wrong lines. The <a class="Type" href="options.html#'foldtext'">'foldtext'</a> option is<br>
normally set such that the text before the marker shows up in the folded line.<br>
This makes it possible to give a name to the fold.<br>
<br>
Markers can have a level included, or can use matching pairs. Including a<br>
level is easier, you don't have to add end markers and avoid problems with<br>
non-matching marker pairs. Example:<br>
<div class="helpExample"> /* global variables {{ "{{{" }}1 */<br>
int varA, varB;</div>
<br>
<div class="helpExample"> /* functions {{ "{{{" }}1 */<br>
/* funcA() {{ "{{{" }}2 */<br>
void funcA() {}</div>
<br>
<div class="helpExample"> /* funcB() {{ "{{{" }}2 */<br>
void funcB() {}</div>
<br>
A fold starts at a "{{ "{{{" }}" marker. The following number specifies the fold<br>
level. What happens depends on the difference between the current fold level<br>
and the level given by the marker:<br>
1. If a marker with the same fold level is encountered, the previous fold<br>
ends and another fold with the same level starts.<br>
2. If a marker with a higher fold level is found, a nested fold is started.<br>
3. If a marker with a lower fold level is found, all folds up to and including<br>
this level end and a fold with the specified level starts.<br>
<br>
The number indicates the fold level. A zero cannot be used (a marker with<br>
level zero is ignored). You can use "}}}" with a digit to indicate the level<br>
of the fold that ends. The fold level of the following line will be one less<br>
than the indicated level. <span class="Todo">Note</span> that Vim doesn't look back to the level of the<br>
matching marker (that would take too much time). Example:<br>
<br>
<div class="helpExample"> {{ "{{{" }}1<br>
fold level here is 1<br>
{{ "{{{" }}3<br>
fold level here is 3<br>
}}}3<br>
fold level here is 2</div>
<br>
You can also use matching pairs of "{{ "{{{" }}" and "}}}" markers to define folds.<br>
Each "{{ "{{{" }}" increases the fold level by one, each "}}}" decreases the fold<br>
level by one. Be careful to keep the markers matching! Example:<br>
<br>
<div class="helpExample"> {{ "{{{" }}<br>
fold level here is 1<br>
{{ "{{{" }}<br>
fold level here is 2<br>
}}}<br>
fold level here is 1</div>
<br>
You can mix using markers with a number and without a number. A useful way of<br>
doing this is to use numbered markers for large folds, and unnumbered markers<br>
locally in a function. For example use level one folds for the sections of<br>
your file like "structure definitions", "local variables" and "functions".<br>
Use level 2 markers for each definition and function, Use unnumbered markers<br>
inside functions. When you make changes in a function to split up folds, you<br>
don't have to renumber the markers.<br>
<br>
The markers can be set with the <a class="Type" href="options.html#'foldmarker'">'foldmarker'</a> option. It is recommended to<br>
keep this at the default value of "{{ "{{" }}<span class="Special">{,}</span>}}", so that files can be exchanged<br>
between Vim users. Only change it when it is required for the file (e.g., it<br>
contains markers from another folding editor, or the default markers cause<br>
trouble for the language of the file).<br>
<br>
<a class="Constant" href="fold.html#fold-create-marker" name="fold-create-marker">fold-create-marker</a><br>
"zf" can be used to create a fold defined by markers. Vim will insert the<br>
markers for you. Vim will append the start and end marker, as specified with<br>
<a class="Type" href="options.html#'foldmarker'">'foldmarker'</a>. The markers are appended to the end of the line.<br>
<a class="Type" href="options.html#'commentstring'">'commentstring'</a> is used if it isn't empty.<br>
This does not work properly when:<br>
- The line already contains a marker with a level number. Vim then doesn't<br>
know what to do.<br>
- Folds nearby use a level number in their marker which gets in the way.<br>
- The line is inside a comment, <a class="Type" href="options.html#'commentstring'">'commentstring'</a> isn't empty and nested<br>
comments don't work. For example with C: adding /* {{ "{{{" }} */ inside a comment<br>
will truncate the existing comment. Either put the marker before or after<br>
the comment, or add the marker manually.<br>
Generally it's not a good idea to let Vim create markers when you already have<br>
markers with a level number.<br>
<br>
<a class="Constant" href="fold.html#fold-delete-marker" name="fold-delete-marker">fold-delete-marker</a><br>
"zd" can be used to delete a fold defined by markers. Vim will delete the<br>
markers for you. Vim will search for the start and end markers, as specified<br>
with <a class="Type" href="options.html#'foldmarker'">'foldmarker'</a>, at the start and end of the fold. When the text around the<br>
marker matches with <a class="Type" href="options.html#'commentstring'">'commentstring'</a>, that text is deleted as well.<br>
This does not work properly when:<br>
- A line contains more than one marker and one of them specifies a level.<br>
Only the first one is removed, without checking if this will have the<br>
desired effect of deleting the fold.<br>
- The marker contains a level number and is used to start or end several folds<br>
at the same time.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
2. Fold commands <a class="Constant" href="fold.html#fold-commands" name="fold-commands">fold-commands</a> <a class="Constant" href="fold.html#E490" name="E490">E490</a><br>
<br>
All folding commands start with "z". Hint: the "z" looks like a folded piece<br>
of paper, if you look at it from the side.<br>
<br>
<br>
<span class="PreProc">CREATING AND DELETING FOLDS</span><br>
<a class="Constant" href="fold.html#zf" name="zf">zf</a> <a class="Constant" href="fold.html#E350" name="E350">E350</a><br>
zf<span class="Special">{motion}</span> or<br>
<span class="Special">{Visual}</span>zf Operator to create a fold.<br>
This only works when <a class="Type" href="options.html#'foldmethod'">'foldmethod'</a> is "manual" or "marker".<br>
The new fold will be closed for the "manual" method.<br>
<a class="Type" href="options.html#'foldenable'">'foldenable'</a> will be set.<br>
Also see <a class="Identifier" href="fold.html#fold-create-marker">fold-create-marker</a>.<br>
<br>
<a class="Constant" href="fold.html#zF" name="zF">zF</a><br>
zF Create a fold for <span class="Special">[count]</span> lines. Works like "zf".<br>
<br>
:<span class="Special">{range}</span>fo[ld] <a class="Constant" href="fold.html#:fold" name=":fold">:fold</a> <a class="Constant" href="fold.html#:fo" name=":fo">:fo</a><br>
Create a fold for the lines in <span class="Special">{range}</span>. Works like "zf".<br>
<br>
<a class="Constant" href="fold.html#zd" name="zd">zd</a> <a class="Constant" href="fold.html#E351" name="E351">E351</a><br>
zd Delete one fold at the cursor. When the cursor is on a folded<br>
line, that fold is deleted. Nested folds are moved one level<br>
up. In Visual mode one level of all folds (partially) in the<br>
selected area are deleted.<br>
Careful: This easily deletes more folds than you expect and<br>
there is no undo for manual folding.<br>
This only works when <a class="Type" href="options.html#'foldmethod'">'foldmethod'</a> is "manual" or "marker".<br>
Also see <a class="Identifier" href="fold.html#fold-delete-marker">fold-delete-marker</a>.<br>
<br>
<a class="Constant" href="fold.html#zD" name="zD">zD</a><br>
zD Delete folds recursively at the cursor. In Visual mode all<br>
folds (partially) in the selected area and all nested folds in<br>
them are deleted.<br>
This only works when <a class="Type" href="options.html#'foldmethod'">'foldmethod'</a> is "manual" or "marker".<br>
Also see <a class="Identifier" href="fold.html#fold-delete-marker">fold-delete-marker</a>.<br>
<br>
<a class="Constant" href="fold.html#zE" name="zE">zE</a> <a class="Constant" href="fold.html#E352" name="E352">E352</a><br>
zE Eliminate all folds in the window.<br>
This only works when <a class="Type" href="options.html#'foldmethod'">'foldmethod'</a> is "manual" or "marker".<br>
Also see <a class="Identifier" href="fold.html#fold-delete-marker">fold-delete-marker</a>.<br>
<br>
<br>
<span class="PreProc">OPENING AND CLOSING FOLDS</span><br>
<br>
A fold smaller than <a class="Type" href="options.html#'foldminlines'">'foldminlines'</a> will always be displayed like it was open.<br>
Therefore the commands below may work differently on small folds.<br>
<br>
<a class="Constant" href="fold.html#zo" name="zo">zo</a><br>
zo Open one fold under the cursor. When a count is given, that<br>
many folds deep will be opened. In Visual mode one level of<br>
folds is opened for all lines in the selected area.<br>
<br>
<a class="Constant" href="fold.html#zO" name="zO">zO</a><br>
zO Open all folds under the cursor recursively. Folds that don't<br>
contain the cursor line are unchanged.<br>
In Visual mode it opens all folds that are in the selected<br>
area, also those that are only partly selected.<br>
<br>
<a class="Constant" href="fold.html#zc" name="zc">zc</a><br>
zc Close one fold under the cursor. When a count is given, that<br>
many folds deep are closed. In Visual mode one level of folds<br>
is closed for all lines in the selected area.<br>
<a class="Type" href="options.html#'foldenable'">'foldenable'</a> will be set.<br>
<br>
<a class="Constant" href="fold.html#zC" name="zC">zC</a><br>
zC Close all folds under the cursor recursively. Folds that<br>
don't contain the cursor line are unchanged.<br>
In Visual mode it closes all folds that are in the selected<br>
area, also those that are only partly selected.<br>
<a class="Type" href="options.html#'foldenable'">'foldenable'</a> will be set.<br>
<br>
<a class="Constant" href="fold.html#za" name="za">za</a><br>
za When on a closed fold: open it. When folds are nested, you<br>
may have to use "za" several times. When a count is given,<br>
that many closed folds are opened.<br>
When on an open fold: close it and set <a class="Type" href="options.html#'foldenable'">'foldenable'</a>. This<br>
will only close one level, since using "za" again will open<br>
the fold. When a count is given that many folds will be<br>
closed (that's not the same as repeating "za" that many<br>
times).<br>
<br>
<a class="Constant" href="fold.html#zA" name="zA">zA</a><br>
zA When on a closed fold: open it recursively.<br>
When on an open fold: close it recursively and set<br>
<a class="Type" href="options.html#'foldenable'">'foldenable'</a>.<br>
<br>
<a class="Constant" href="fold.html#zv" name="zv">zv</a><br>
zv View cursor line: Open just enough folds to make the line in<br>
which the cursor is located not folded.<br>
<br>
<a class="Constant" href="fold.html#zx" name="zx">zx</a><br>
zx Update folds: Undo manually opened and closed folds: re-apply<br>
<a class="Type" href="options.html#'foldlevel'">'foldlevel'</a>, then do "zv": View cursor line.<br>
Also forces recomputing folds. This is useful when using<br>
<a class="Type" href="options.html#'foldexpr'">'foldexpr'</a> and the buffer is changed in a way that results in<br>
folds not to be updated properly.<br>
<br>
<a class="Constant" href="fold.html#zX" name="zX">zX</a><br>
zX Undo manually opened and closed folds: re-apply <a class="Type" href="options.html#'foldlevel'">'foldlevel'</a>.<br>
Also forces recomputing folds, like <a class="Identifier" href="fold.html#zx">zx</a>.<br>
<br>
<a class="Constant" href="fold.html#zm" name="zm">zm</a><br>
zm Fold more: Subtract <a class="Identifier" href="eval.html#v:count1">v:count1</a> from <a class="Type" href="options.html#'foldlevel'">'foldlevel'</a>. If <a class="Type" href="options.html#'foldlevel'">'foldlevel'</a> was<br>
already zero nothing happens.<br>
<a class="Type" href="options.html#'foldenable'">'foldenable'</a> will be set.<br>
<br>
<a class="Constant" href="fold.html#zM" name="zM">zM</a><br>
zM Close all folds: set <a class="Type" href="options.html#'foldlevel'">'foldlevel'</a> to 0.<br>
<a class="Type" href="options.html#'foldenable'">'foldenable'</a> will be set.<br>
<br>
<a class="Constant" href="fold.html#zr" name="zr">zr</a><br>
zr Reduce folding: Add <a class="Identifier" href="eval.html#v:count1">v:count1</a> to <a class="Type" href="options.html#'foldlevel'">'foldlevel'</a>.<br>
<br>
<a class="Constant" href="fold.html#zR" name="zR">zR</a><br>
zR Open all folds. This sets <a class="Type" href="options.html#'foldlevel'">'foldlevel'</a> to highest fold level.<br>
<br>
<a class="Constant" href="fold.html#:foldo" name=":foldo">:foldo</a> <a class="Constant" href="fold.html#:foldopen" name=":foldopen">:foldopen</a><br>
:<span class="Special">{range}</span>foldo[pen][!]<br>
Open folds in <span class="Special">{range}</span>. When [!] is added all folds are<br>
opened. Useful to see all the text in <span class="Special">{range}</span>. Without [!]<br>
one level of folds is opened.<br>
<br>
<a class="Constant" href="fold.html#:foldc" name=":foldc">:foldc</a> <a class="Constant" href="fold.html#:foldclose" name=":foldclose">:foldclose</a><br>
:<span class="Special">{range}</span>foldc[lose][!]<br>
Close folds in <span class="Special">{range}</span>. When [!] is added all folds are<br>
closed. Useful to hide all the text in <span class="Special">{range}</span>. Without [!]<br>
one level of folds is closed.<br>
<br>
<a class="Constant" href="fold.html#zn" name="zn">zn</a><br>
zn Fold none: reset <a class="Type" href="options.html#'foldenable'">'foldenable'</a>. All folds will be open.<br>
<br>
<a class="Constant" href="fold.html#zN" name="zN">zN</a><br>
zN Fold normal: set <a class="Type" href="options.html#'foldenable'">'foldenable'</a>. All folds will be as they<br>
were before.<br>
<br>
<a class="Constant" href="fold.html#zi" name="zi">zi</a><br>
zi Invert <a class="Type" href="options.html#'foldenable'">'foldenable'</a>.<br>
<br>
<br>
<span class="PreProc">MOVING OVER FOLDS</span><br>
<a class="Constant" href="fold.html#[z" name="[z">[z</a><br>
[z Move to the start of the current open fold. If already at the<br>
start, move to the start of the fold that contains it. If<br>
there is no containing fold, the command fails.<br>
When a count is used, repeats the command <span class="Special">[count]</span> times.<br>
<br>
<a class="Constant" href="fold.html#]z" name="]z">]z</a><br>
]z Move to the end of the current open fold. If already at the<br>
end, move to the end of the fold that contains it. If there<br>
is no containing fold, the command fails.<br>
When a count is used, repeats the command <span class="Special">[count]</span> times.<br>
<br>
<a class="Constant" href="fold.html#zj" name="zj">zj</a><br>
zj Move downwards to the start of the next fold. A closed fold<br>
is counted as one fold.<br>
When a count is used, repeats the command <span class="Special">[count]</span> times.<br>
This command can be used after an <a class="Identifier" href="motion.html#operator">operator</a>.<br>
<br>
<a class="Constant" href="fold.html#zk" name="zk">zk</a><br>
zk Move upwards to the end of the previous fold. A closed fold<br>
is counted as one fold.<br>
When a count is used, repeats the command <span class="Special">[count]</span> times.<br>
This command can be used after an <a class="Identifier" href="motion.html#operator">operator</a>.<br>
<br>
<br>
<span class="PreProc">EXECUTING COMMANDS ON FOLDS</span><br>
<br>
:<span class="Special">[range]</span>foldd[oopen] <span class="Special">{cmd}</span> <a class="Constant" href="fold.html#:foldd" name=":foldd">:foldd</a> <a class="Constant" href="fold.html#:folddoopen" name=":folddoopen">:folddoopen</a><br>
Execute <span class="Special">{cmd}</span> on all lines that are not in a closed fold.<br>
When <span class="Special">[range]</span> is given, only these lines are used.<br>
Each time <span class="Special">{cmd}</span> is executed the cursor is positioned on the<br>
line it is executed for.<br>
This works like the ":global" command: First all lines that<br>
are not in a closed fold are marked. Then the <span class="Special">{cmd}</span> is<br>
executed for all marked lines. Thus when <span class="Special">{cmd}</span> changes the<br>
folds, this has no influence on where it is executed (except<br>
when lines are deleted, of course).<br>
Example:<br>
<div class="helpExample"> :folddoopen s/end/loop_end/ge</div>
<span class="Todo">Note</span> the use of the "e" flag to avoid getting an error message<br>
where "end" doesn't match.<br>
<br>
:<span class="Special">[range]</span>folddoc[losed] <span class="Special">{cmd}</span> <a class="Constant" href="fold.html#:folddoc" name=":folddoc">:folddoc</a> <a class="Constant" href="fold.html#:folddoclosed" name=":folddoclosed">:folddoclosed</a><br>
Execute <span class="Special">{cmd}</span> on all lines that are in a closed fold.<br>
Otherwise like ":folddoopen".<br>
<br>
<span class="PreProc">==============================================================================</span><br>
3. Fold options <a class="Constant" href="fold.html#fold-options" name="fold-options">fold-options</a><br>
<br>
<span class="Statement">COLORS </span><a class="Constant" href="fold.html#fold-colors" name="fold-colors">fold-colors</a><br>
<br>
The colors of a closed fold are set with the Folded group <a class="Identifier" href="syntax.html#hl-Folded">hl-Folded</a>. The<br>
colors of the fold column are set with the FoldColumn group <a class="Identifier" href="syntax.html#hl-FoldColumn">hl-FoldColumn</a>.<br>
Example to set the colors:<br>
<br>
<div class="helpExample"> :highlight Folded guibg=grey guifg=blue<br>
:highlight FoldColumn guibg=darkgrey guifg=white</div>
<br>
<br>
<span class="Statement">FOLDLEVEL </span><a class="Constant" href="fold.html#fold-foldlevel" name="fold-foldlevel">fold-foldlevel</a><br>
<br>
<a class="Type" href="options.html#'foldlevel'">'foldlevel'</a> is a number option: The higher the more folded regions are open.<br>
When <a class="Type" href="options.html#'foldlevel'">'foldlevel'</a> is 0, all folds are closed.<br>
When <a class="Type" href="options.html#'foldlevel'">'foldlevel'</a> is positive, some folds are closed.<br>
When <a class="Type" href="options.html#'foldlevel'">'foldlevel'</a> is very high, all folds are open.<br>
<a class="Type" href="options.html#'foldlevel'">'foldlevel'</a> is applied when it is changed. After that manually folds can be<br>
opened and closed.<br>
When increased, folds above the new level are opened. No manually opened<br>
folds will be closed.<br>
When decreased, folds above the new level are closed. No manually closed<br>
folds will be opened.<br>
<br>
<br>
<span class="Statement">FOLDTEXT </span><a class="Constant" href="fold.html#fold-foldtext" name="fold-foldtext">fold-foldtext</a><br>
<br>
<a class="Type" href="options.html#'foldtext'">'foldtext'</a> is a string option that specifies an expression. This expression<br>
is evaluated to obtain the text displayed for a closed fold. Example:<br>
<br>
<div class="helpExample"> :set foldtext=v:folddashes.substitute(getline(v:foldstart),'/\\*\\\|\\*/\\\|{{ "{{{" }}\\d\\=','','g')</div>
<br>
This shows the first line of the fold, with "/*", "*/" and "{{ "{{{" }}" removed.<br>
<span class="Todo">Note</span> the use of backslashes to avoid some characters to be interpreted by the<br>
":set" command. It's simpler to define a function and call that:<br>
<br>
<div class="helpExample"> :set foldtext=MyFoldText()<br>
:function MyFoldText()<br>
: let line = getline(v:foldstart)<br>
: let sub = substitute(line, '/\*\|\*/\|{{ "{{{" }}\d\=', '', 'g')<br>
: return v:folddashes . sub<br>
:endfunction</div>
<br>
Evaluating <a class="Type" href="options.html#'foldtext'">'foldtext'</a> is done in the <a class="Identifier" href="eval.html#sandbox">sandbox</a>. The current window is set to<br>
the window that displays the line. Errors are ignored.<br>
<br>
The default value is <a class="Identifier" href="eval.html#foldtext()">foldtext()</a>. This returns a reasonable text for most<br>
types of folding. If you don't like it, you can specify your own <a class="Type" href="options.html#'foldtext'">'foldtext'</a><br>
expression. It can use these special Vim variables:<br>
v:foldstart line number of first line in the fold<br>
v:foldend line number of last line in the fold<br>
v:folddashes a string that contains dashes to represent the<br>
foldlevel.<br>
v:foldlevel the foldlevel of the fold<br>
<br>
In the result a TAB is replaced with a space and unprintable characters are<br>
made into printable characters.<br>
<br>
The resulting line is truncated to fit in the window, it never wraps.<br>
When there is room after the text, it is filled with the character specified<br>
by <a class="Type" href="options.html#'fillchars'">'fillchars'</a>.<br>
<br>
<span class="Todo">Note</span> that backslashes need to be used for characters that the ":set" command<br>
handles differently: Space, backslash and double-quote. <a class="Identifier" href="options.html#option-backslash">option-backslash</a><br>
<br>
<br>
<span class="Statement">FOLDCOLUMN </span><a class="Constant" href="fold.html#fold-foldcolumn" name="fold-foldcolumn">fold-foldcolumn</a><br>
<br>
<a class="Type" href="options.html#'foldcolumn'">'foldcolumn'</a> is a number, which sets the width for a column on the side of the<br>
window to indicate folds. When it is zero, there is no foldcolumn. A normal<br>
value is 4 or 5. The minimal useful value is 2, although 1 still provides<br>
some information. The maximum is 12.<br>
<br>
An open fold is indicated with a column that has a '-' at the top and '|'<br>
characters below it. This column stops where the open fold stops. When folds<br>
nest, the nested fold is one character right of the fold it's contained in.<br>
<br>
A closed fold is indicated with a '+'.<br>
<br>
Where the fold column is too narrow to display all nested folds, digits are<br>
shown to indicate the nesting level.<br>
<br>
The mouse can also be used to open and close folds by clicking in the<br>
fold column:<br>
- Click on a '+' to open the closed fold at this row.<br>
- Click on any other non-blank character to close the open fold at this row.<br>
<br>
<br>
OTHER OPTIONS<br>
<br>
<a class="Type" href="options.html#'foldenable'">'foldenable'</a> <a class="Type" href="options.html#'fen'">'fen'</a>: Open all folds while not set.<br>
<a class="Type" href="options.html#'foldexpr'">'foldexpr'</a> <a class="Type" href="options.html#'fde'">'fde'</a>: Expression used for "expr" folding.<br>
<a class="Type" href="options.html#'foldignore'">'foldignore'</a> <a class="Type" href="options.html#'fdi'">'fdi'</a>: Characters used for "indent" folding.<br>
<a class="Type" href="options.html#'foldmarker'">'foldmarker'</a> <a class="Type" href="options.html#'fmr'">'fmr'</a>: Defined markers used for "marker" folding.<br>
<a class="Type" href="options.html#'foldmethod'">'foldmethod'</a> <a class="Type" href="options.html#'fdm'">'fdm'</a>: Name of the current folding method.<br>
<a class="Type" href="options.html#'foldminlines'">'foldminlines'</a> <a class="Type" href="options.html#'fml'">'fml'</a>: Minimum number of screen lines for a fold to be<br>
displayed closed.<br>
<a class="Type" href="options.html#'foldnestmax'">'foldnestmax'</a> <a class="Type" href="options.html#'fdn'">'fdn'</a>: Maximum nesting for "indent" and "syntax" folding.<br>
<a class="Type" href="options.html#'foldopen'">'foldopen'</a> <a class="Type" href="options.html#'fdo'">'fdo'</a>: Which kinds of commands open closed folds.<br>
<a class="Type" href="options.html#'foldclose'">'foldclose'</a> <a class="Type" href="options.html#'fcl'">'fcl'</a>: When the folds not under the cursor are closed.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
4. Behavior of folds <a class="Constant" href="fold.html#fold-behavior" name="fold-behavior">fold-behavior</a><br>
<br>
When moving the cursor upwards or downwards and when scrolling, the cursor<br>
will move to the first line of a sequence of folded lines. When the cursor is<br>
already on a folded line, it moves to the next unfolded line or the next<br>
closed fold.<br>
<br>
While the cursor is on folded lines, the cursor is always displayed in the<br>
first column. The ruler does show the actual cursor position, but since the<br>
line is folded, it cannot be displayed there.<br>
<br>
Many movement commands handle a sequence of folded lines like an empty line.<br>
For example, the "w" command stops once in the first column.<br>
<br>
When in Insert mode, the cursor line is never folded. That allows you to see<br>
what you type!<br>
<br>
When using an operator, a closed fold is included as a whole. Thus "dl"<br>
deletes the whole closed fold under the cursor.<br>
<br>
For Ex commands that work on buffer lines the range is adjusted to always<br>
start at the first line of a closed fold and end at the last line of a closed<br>
fold. Thus this command:<br>
<div class="helpExample"> :s/foo/bar/g</div>
when used with the cursor on a closed fold, will replace "foo" with "bar" in<br>
all lines of the fold.<br>
This does not happen for <a class="Identifier" href="fold.html#:folddoopen">:folddoopen</a> and <a class="Identifier" href="fold.html#:folddoclosed">:folddoclosed</a>.<br>
<br>
When editing a buffer that has been edited before, the last used folding<br>
settings are used again. For manual folding the defined folds are restored.<br>
For all folding methods the manually opened and closed folds are restored.<br>
If this buffer has been edited in this window, the values from back then are<br>
used. Otherwise the values from the window where the buffer was edited last<br>
are used.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
vim:tw=78:ts=8:ft=help:norl:<br>
</div>
</article>
<footer>
<a href="#top">Return to the top</a> - <a href="index.html">Return to main</a>
<span class="EnglishJapaneseLink">
<span class="CurrentLanguage">English</span>
</span>
<br />
<div style="text-align:right;">
Hosted by <a href="https://github.com/vim-jp/vimdoc-en">vimdoc-en project</a><br />
If you met any problem, please report it to <a href="https://github.com/vim-jp/vimdoc-en/issues">issue</a>.<br />
</div>
</footer>
<!--<script src="js/check-referrer.js" type="text/javascript"></script>-->
</body>
</html>
<!-- vim:set ts=8 sts=2 sw=2 tw=0 et: -->
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。