代码拉取完成,页面将自动刷新
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>usr_28 - 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>
/ usr_28<br />
<a name="top"></a><h1>usr_28 - 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="usr_28.html" name="usr_28.txt">usr_28.txt</a> For <span class="Identifier">Vim version 8.0.</span> Last change: 2008 Jun 14<br>
<br>
VIM USER MANUAL - by Bram Moolenaar<br>
<br>
Folding<br>
<br>
<br>
Structured text can be separated in sections. And sections in sub-sections.<br>
Folding allows you to display a section as one line, providing an overview.<br>
This chapter explains the different ways this can be done.<br>
<br>
<a class="Identifier" href="usr_28.html#28.1">28.1</a> What is folding?<br>
<a class="Identifier" href="usr_28.html#28.2">28.2</a> Manual folding<br>
<a class="Identifier" href="usr_28.html#28.3">28.3</a> Working with folds<br>
<a class="Identifier" href="usr_28.html#28.4">28.4</a> Saving and restoring folds<br>
<a class="Identifier" href="usr_28.html#28.5">28.5</a> Folding by indent<br>
<a class="Identifier" href="usr_28.html#28.6">28.6</a> Folding with markers<br>
<a class="Identifier" href="usr_28.html#28.7">28.7</a> Folding by syntax<br>
<a class="Identifier" href="usr_28.html#28.8">28.8</a> Folding by expression<br>
<a class="Identifier" href="usr_28.html#28.9">28.9</a> Folding unchanged lines<br>
<a class="Identifier" href="usr_28.html#28.10">28.10</a> Which fold method to use?<br>
<br>
Next chapter: <a class="Identifier" href="usr_29.html">usr_29.txt</a> Moving through programs<br>
Previous chapter: <a class="Identifier" href="usr_27.html">usr_27.txt</a> Search commands and patterns<br>
Table of contents: <a class="Identifier" href="usr_toc.html">usr_toc.txt</a><br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_28.html#28.1" name="28.1">28.1</a> What is folding?<br>
<br>
Folding is used to show a range of lines in the buffer as a single line on the<br>
screen. Like a piece of paper which is folded to make it shorter:<br>
<br>
+------------------------+<br>
| line 1 |<br>
| line 2 |<br>
| line 3 |<br>
|_______________________ |<br>
\ \<br>
\________________________\<br>
/ folded lines /<br>
/________________________/<br>
| line 12 |<br>
| line 13 |<br>
| line 14 |<br>
+------------------------+<br>
<br>
The text is still in the buffer, unchanged. Only the way lines are displayed<br>
is affected by folding.<br>
<br>
The advantage of folding is that you can get a better overview of the<br>
structure of text, by folding lines of a section and replacing it with a line<br>
that indicates that there is a section.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_28.html#28.2" name="28.2">28.2</a> Manual folding<br>
<br>
Try it out: Position the cursor in a paragraph and type:<br>
<br>
<div class="helpExample"> zfap</div>
<br>
You will see that the paragraph is replaced by a highlighted line. You have<br>
created a fold. <a class="Identifier" href="fold.html#zf">zf</a> is an operator and <a class="Identifier" href="motion.html#ap">ap</a> a text object selection. You<br>
can use the <a class="Identifier" href="fold.html#zf">zf</a> operator with any movement command to create a fold for the<br>
text that it moved over. <a class="Identifier" href="fold.html#zf">zf</a> also works in Visual mode.<br>
<br>
To view the text again, open the fold by typing:<br>
<br>
<div class="helpExample"> zo</div>
<br>
And you can close the fold again with:<br>
<br>
<div class="helpExample"> zc</div>
<br>
All the folding commands start with "z". With some fantasy, this looks like a<br>
folded piece of paper, seen from the side. The letter after the "z" has a<br>
mnemonic meaning to make it easier to remember the commands:<br>
<br>
zf F-old creation<br>
zo O-pen a fold<br>
zc C-lose a fold<br>
<br>
Folds can be nested: A region of text that contains folds can be folded<br>
again. For example, you can fold each paragraph in this section, and then<br>
fold all the sections in this chapter. Try it out. You will notice that<br>
opening the fold for the whole chapter will restore the nested folds as they<br>
were, some may be open and some may be closed.<br>
<br>
Suppose you have created several folds, and now want to view all the text.<br>
You could go to each fold and type "zo". To do this faster, use this command:<br>
<br>
<div class="helpExample"> zr</div>
<br>
This will R-educe the folding. The opposite is:<br>
<br>
<div class="helpExample"> zm</div>
<br>
This folds M-ore. You can repeat "zr" and "zm" to open and close nested folds<br>
of several levels.<br>
<br>
If you have nested several levels deep, you can open all of them with:<br>
<br>
<div class="helpExample"> zR</div>
<br>
This R-educes folds until there are none left. And you can close all folds<br>
with:<br>
<br>
<div class="helpExample"> zM</div>
<br>
This folds M-ore and M-ore.<br>
<br>
You can quickly disable the folding with the <a class="Identifier" href="fold.html#zn">zn</a> command. Then <a class="Identifier" href="fold.html#zN">zN</a> brings<br>
back the folding as it was. <a class="Identifier" href="fold.html#zi">zi</a> toggles between the two. This is a useful<br>
way of working:<br>
- create folds to get overview on your file<br>
- move around to where you want to do your work<br>
- do <a class="Identifier" href="fold.html#zi">zi</a> to look at the text and edit it<br>
- do <a class="Identifier" href="fold.html#zi">zi</a> again to go back to moving around<br>
<br>
More about manual folding in the reference manual: <a class="Identifier" href="fold.html#fold-manual">fold-manual</a><br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_28.html#28.3" name="28.3">28.3</a> Working with folds<br>
<br>
When some folds are closed, movement commands like "j" and "k" move over a<br>
fold like it was a single, empty line. This allows you to quickly move around<br>
over folded text.<br>
<br>
You can yank, delete and put folds as if it was a single line. This is very<br>
useful if you want to reorder functions in a program. First make sure that<br>
each fold contains a whole function (or a bit less) by selecting the right<br>
<a class="Type" href="options.html#'foldmethod'">'foldmethod'</a>. Then delete the function with "dd", move the cursor and put it<br>
with "p". If some lines of the function are above or below the fold, you can<br>
use Visual selection:<br>
- put the cursor on the first line to be moved<br>
- hit "V" to start Visual mode<br>
- put the cursor on the last line to be moved<br>
- hit "d" to delete the selected lines.<br>
- move the cursor to the new position and "p"ut the lines there.<br>
<br>
It is sometimes difficult to see or remember where a fold is located, thus<br>
where a <a class="Identifier" href="fold.html#zo">zo</a> command would actually work. To see the defined folds:<br>
<br>
<div class="helpExample"> :set foldcolumn=4</div>
<br>
This will show a small column on the left of the window to indicate folds.<br>
A "+" is shown for a closed fold. A "-" is shown at the start of each open<br>
fold and "|" at following lines of the fold.<br>
<br>
You can use the mouse to open a fold by clicking on the "+" in the foldcolumn.<br>
Clicking on the "-" or a "|" below it will close an open fold.<br>
<br>
To open all folds at the cursor line use <a class="Identifier" href="fold.html#zO">zO</a>.<br>
To close all folds at the cursor line use <a class="Identifier" href="fold.html#zC">zC</a>.<br>
To delete a fold at the cursor line use <a class="Identifier" href="fold.html#zd">zd</a>.<br>
To delete all folds at the cursor line use <a class="Identifier" href="fold.html#zD">zD</a>.<br>
<br>
When in Insert mode, the fold at the cursor line is never closed. That allows<br>
you to see what you type!<br>
<br>
Folds are opened automatically when jumping around or moving the cursor left<br>
or right. For example, the "0" command opens the fold under the cursor<br>
(if <a class="Type" href="options.html#'foldopen'">'foldopen'</a> contains "hor", which is the default). The <a class="Type" href="options.html#'foldopen'">'foldopen'</a> option<br>
can be changed to open folds for specific commands. If you want the line<br>
under the cursor always to be open, do this:<br>
<br>
<div class="helpExample"> :set foldopen=all</div>
<br>
Warning: You won't be able to move onto a closed fold then. You might want to<br>
use this only temporarily and then set it back to the default:<br>
<br>
<div class="helpExample"> :set foldopen&</div>
<br>
You can make folds close automatically when you move out of it:<br>
<br>
<div class="helpExample"> :set foldclose=all</div>
<br>
This will re-apply <a class="Type" href="options.html#'foldlevel'">'foldlevel'</a> to all folds that don't contain the cursor.<br>
You have to try it out if you like how this feels. Use <a class="Identifier" href="fold.html#zm">zm</a> to fold more and<br>
<a class="Identifier" href="fold.html#zr">zr</a> to fold less (reduce folds).<br>
<br>
The folding is local to the window. This allows you to open two windows on<br>
the same buffer, one with folds and one without folds. Or one with all folds<br>
closed and one with all folds open.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_28.html#28.4" name="28.4">28.4</a> Saving and restoring folds<br>
<br>
When you abandon a file (starting to edit another one), the state of the folds<br>
is lost. If you come back to the same file later, all manually opened and<br>
closed folds are back to their default. When folds have been created<br>
manually, all folds are gone! To save the folds use the <a class="Identifier" href="starting.html#:mkview">:mkview</a> command:<br>
<br>
<div class="helpExample"> :mkview</div>
<br>
This will store the settings and other things that influence the view on the<br>
file. You can change what is stored with the <a class="Type" href="options.html#'viewoptions'">'viewoptions'</a> option.<br>
When you come back to the same file later, you can load the view again:<br>
<br>
<div class="helpExample"> :loadview</div>
<br>
You can store up to ten views on one file. For example, to save the current<br>
setup as the third view and load the second view:<br>
<br>
<div class="helpExample"> :mkview 3<br>
:loadview 2</div>
<br>
<span class="Todo">Note</span> that when you insert or delete lines the views might become invalid.<br>
Also check out the <a class="Type" href="options.html#'viewdir'">'viewdir'</a> option, which specifies where the views are<br>
stored. You might want to delete old views now and then.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_28.html#28.5" name="28.5">28.5</a> Folding by indent<br>
<br>
Defining folds with <a class="Identifier" href="fold.html#zf">zf</a> is a lot of work. If your text is structured by<br>
giving lower level items a larger indent, you can use the indent folding<br>
method. This will create folds for every sequence of lines with the same<br>
indent. Lines with a larger indent will become nested folds. This works well<br>
with many programming languages.<br>
<br>
Try this by setting the <a class="Type" href="options.html#'foldmethod'">'foldmethod'</a> option:<br>
<br>
<div class="helpExample"> :set foldmethod=indent</div>
<br>
Then you can use the <a class="Identifier" href="fold.html#zm">zm</a> and <a class="Identifier" href="fold.html#zr">zr</a> commands to fold more and reduce folding.<br>
It's easy to see on this example text:<br>
<br>
This line is not indented<br>
This line is indented once<br>
This line is indented twice<br>
This line is indented twice<br>
This line is indented once<br>
This line is not indented<br>
This line is indented once<br>
This line is indented once<br>
<br>
<span class="Todo">Note</span> that the relation between the amount of indent and the fold depth depends<br>
on the <a class="Type" href="options.html#'shiftwidth'">'shiftwidth'</a> option. Each <a class="Type" href="options.html#'shiftwidth'">'shiftwidth'</a> worth of indent adds one to the<br>
depth of the fold. This is called a fold level.<br>
<br>
When you use the <a class="Identifier" href="fold.html#zr">zr</a> and <a class="Identifier" href="fold.html#zm">zm</a> commands you actually increase or decrease the<br>
<a class="Type" href="options.html#'foldlevel'">'foldlevel'</a> option. You could also set it directly:<br>
<br>
<div class="helpExample"> :set foldlevel=3</div>
<br>
This means that all folds with three times a <a class="Type" href="options.html#'shiftwidth'">'shiftwidth'</a> indent or more will<br>
be closed. The lower the foldlevel, the more folds will be closed. When<br>
<a class="Type" href="options.html#'foldlevel'">'foldlevel'</a> is zero, all folds are closed. <a class="Identifier" href="fold.html#zM">zM</a> does set <a class="Type" href="options.html#'foldlevel'">'foldlevel'</a> to zero.<br>
The opposite command <a class="Identifier" href="fold.html#zR">zR</a> sets <a class="Type" href="options.html#'foldlevel'">'foldlevel'</a> to the deepest fold level that is<br>
present in the file.<br>
<br>
Thus there are two ways to open and close the folds:<br>
(A) By setting the fold level.<br>
This gives a very quick way of "zooming out" to view the structure of the<br>
text, move the cursor, and "zoom in" on the text again.<br>
<br>
(B) By using <a class="Identifier" href="fold.html#zo">zo</a> and <a class="Identifier" href="fold.html#zc">zc</a> commands to open or close specific folds.<br>
This allows opening only those folds that you want to be open, while other<br>
folds remain closed.<br>
<br>
This can be combined: You can first close most folds by using <a class="Identifier" href="fold.html#zm">zm</a> a few times<br>
and then open a specific fold with <a class="Identifier" href="fold.html#zo">zo</a>. Or open all folds with <a class="Identifier" href="fold.html#zR">zR</a> and<br>
then close specific folds with <a class="Identifier" href="fold.html#zc">zc</a>.<br>
<br>
But you cannot manually define folds when <a class="Type" href="options.html#'foldmethod'">'foldmethod'</a> is "indent", as that<br>
would conflict with the relation between the indent and the fold level.<br>
<br>
More about folding by indent in the reference manual: <a class="Identifier" href="fold.html#fold-indent">fold-indent</a><br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_28.html#28.6" name="28.6">28.6</a> Folding with markers<br>
<br>
Markers in the text are used to specify the start and end of a fold region.<br>
This gives precise control over which lines are included in a fold. The<br>
disadvantage is that the text needs to be modified.<br>
<br>
Try it:<br>
<br>
<div class="helpExample"> :set foldmethod=marker</div>
<br>
Example text, as it could appear in a C program:<br>
<br>
/* foobar () {{ "{{{" }} */<br>
int foobar()<br>
{<br>
/* return a value {{ "{{{" }} */<br>
return 42;<br>
/* }}} */<br>
}<br>
/* }}} */<br>
<br>
Notice that the folded line will display the text before the marker. This is<br>
very useful to tell what the fold contains.<br>
<br>
It's quite annoying when the markers don't pair up correctly after moving some<br>
lines around. This can be avoided by using numbered markers. Example:<br>
<br>
/* global variables {{ "{{{" }}1 */<br>
int varA, varB;<br>
<br>
/* functions {{ "{{{" }}1 */<br>
/* funcA() {{ "{{{" }}2 */<br>
void funcA() {}<br>
<br>
/* funcB() {{ "{{{" }}2 */<br>
void funcB() {}<br>
/* }}}1 */<br>
<br>
At every numbered marker a fold at the specified level begins. This will make<br>
any fold at a higher level stop here. You can just use numbered start markers<br>
to define all folds. Only when you want to explicitly stop a fold before<br>
another starts you need to add an end marker.<br>
<br>
More about folding with markers in the reference manual: <a class="Identifier" href="fold.html#fold-marker">fold-marker</a><br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_28.html#28.7" name="28.7">28.7</a> Folding by syntax<br>
<br>
For each language Vim uses a different syntax file. This defines the colors<br>
for various items in the file. If you are reading this in Vim, in a terminal<br>
that supports colors, the colors you see are made with the "help" syntax file.<br>
In the syntax files it is possible to add syntax items that have the "fold"<br>
argument. These define a fold region. This requires writing a syntax file<br>
and adding these items in it. That's not so easy to do. But once it's done,<br>
all folding happens automatically.<br>
Here we'll assume you are using an existing syntax file. Then there is<br>
nothing more to explain. You can open and close folds as explained above.<br>
The folds will be created and deleted automatically when you edit the file.<br>
<br>
More about folding by syntax in the reference manual: <a class="Identifier" href="fold.html#fold-syntax">fold-syntax</a><br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_28.html#28.8" name="28.8">28.8</a> Folding by expression<br>
<br>
This is similar to folding by indent, but instead of using the indent of a<br>
line a user function is called to compute the fold level of a line. You can<br>
use this for text where something in the text indicates which lines belong<br>
together. An example is an e-mail message where the quoted text is indicated<br>
by a ">" before the line. To fold these quotes use this:<br>
<br>
<div class="helpExample"> :set foldmethod=expr<br>
:set foldexpr=strlen(substitute(substitute(getline(v:lnum),'\\s','',\"g\"),'[^>].*','',''))</div>
<br>
You can try it out on this text:<br>
<br>
> quoted text he wrote<br>
> quoted text he wrote<br>
> > double quoted text I wrote<br>
> > double quoted text I wrote<br>
<br>
Explanation for the <a class="Type" href="options.html#'foldexpr'">'foldexpr'</a> used in the example (inside out):<br>
getline(v:lnum) gets the current line<br>
substitute(...,'\\s','','g') removes all white space from the line<br>
substitute(...,'[^>].*','','') removes everything after leading '>'s<br>
strlen(...) counts the length of the string, which<br>
is the number of '>'s found<br>
<br>
<span class="Todo">Note</span> that a backslash must be inserted before every space, double quote and<br>
backslash for the ":set" command. If this confuses you, do<br>
<br>
<div class="helpExample"> :set foldexpr</div>
<br>
to check the actual resulting value. To correct a complicated expression, use<br>
the command-line completion:<br>
<br>
<div class="helpExample"> :set foldexpr=<Tab></div>
<br>
Where <span class="Special"><Tab></span> is a real Tab. Vim will fill in the previous value, which you can<br>
then edit.<br>
<br>
When the expression gets more complicated you should put it in a function and<br>
set <a class="Type" href="options.html#'foldexpr'">'foldexpr'</a> to call that function.<br>
<br>
More about folding by expression in the reference manual: <a class="Identifier" href="fold.html#fold-expr">fold-expr</a><br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_28.html#28.9" name="28.9">28.9</a> Folding unchanged lines<br>
<br>
This is useful when you set the <a class="Type" href="options.html#'diff'">'diff'</a> option in the same window. The<br>
<a class="Identifier" href="diff.html#vimdiff">vimdiff</a> command does this for you. Example:<br>
<br>
<div class="helpExample"> :setlocal diff foldmethod=diff scrollbind nowrap foldlevel=1</div>
<br>
Do this in every window that shows a different version of the same file. You<br>
will clearly see the differences between the files, while the text that didn't<br>
change is folded.<br>
<br>
For more details see <a class="Identifier" href="fold.html#fold-diff">fold-diff</a>.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_28.html#28.10" name="28.10">28.10</a> Which fold method to use?<br>
<br>
All these possibilities make you wonder which method you should choose.<br>
Unfortunately, there is no golden rule. Here are some hints.<br>
<br>
If there is a syntax file with folding for the language you are editing, that<br>
is probably the best choice. If there isn't one, you might try to write it.<br>
This requires a good knowledge of search patterns. It's not easy, but when<br>
it's working you will not have to define folds manually.<br>
<br>
Typing commands to manually fold regions can be used for unstructured text.<br>
Then use the <a class="Identifier" href="starting.html#:mkview">:mkview</a> command to save and restore your folds.<br>
<br>
The marker method requires you to change the file. If you are sharing the<br>
files with other people or you have to meet company standards, you might not<br>
be allowed to add them.<br>
The main advantage of markers is that you can put them exactly where you<br>
want them. That avoids that a few lines are missed when you cut and paste<br>
folds. And you can add a comment about what is contained in the fold.<br>
<br>
Folding by indent is something that works in many files, but not always very<br>
well. Use it when you can't use one of the other methods. However, it is<br>
very useful for outlining. Then you specifically use one <a class="Type" href="options.html#'shiftwidth'">'shiftwidth'</a> for<br>
each nesting level.<br>
<br>
Folding with expressions can make folds in almost any structured text. It is<br>
quite simple to specify, especially if the start and end of a fold can easily<br>
be recognized.<br>
If you use the "expr" method to define folds, but they are not exactly how<br>
you want them, you could switch to the "manual" method. This will not remove<br>
the defined folds. Then you can delete or add folds manually.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<br>
Next chapter: <a class="Identifier" href="usr_29.html">usr_29.txt</a> Moving through programs<br>
<br>
Copyright: see <a class="Identifier" href="usr_01.html#manual-copyright">manual-copyright</a> 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: -->
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。