Transferred from: http://www.2cto.com/os/201203/122133.html
Main command:
zf-creating a collapsed
zf20g--create collapse, collapse from current line to line 20th
zfgg--creates a collapsed, collapsed from the current position to the file header, perfect for programming when hiding files at the top of the header file containing, source file comments
The program is written in the function unit, it is convenient to collapse a function, and retain the function head. In the following function, we hover the cursor at {, enter zf% (% in vim to denote parentheses match, here refers to match to another corresponding brace)
#include <stdio.h>
int main (int argc, char* argv[])
{
return 0;
}
The effect comes out:
#include <stdio.h>
int main (int argc, char* argv[])
+:--3 rows {-------------------------------------------------}
To read those text again, you can type the following command to open the collapsed:
Zo
You can also use the command to close the folding:
Zc
All the collapsed commands start with ' Z '. Unfold your imagination, this letter looks like a folded up
The side of the paper. The letters that are available after "Z" are easy to remember due to the use of the Help memory method selection:
ZF F-old creation (Create folding)
zo O-pen a fold (open fold)
ZC C-lose a fold (off folding)
Open all folds at once:
ZR ZR (for recursive folding, function similar to ZR)
Close all folds at once:
ZM ZM (for recursive folding, the function is similar to ZM)
More commonly used commands:
Zi (when we have created a collapse, you can use Zi to close all folds, move the cursor to the text you want to browse, and press Zi to open all folds)
Folding Control:
Sometimes it's not easy to see or remember where a fold is. let alone |zo|. command to open it. To check
Look at those defined folds:
: Set foldcolumn=4
This command will display a small bar on the left side of the window to identify the individual folds. A "+" indicates a closed collapse. One
A "-" represents the beginning of each open collapsed, and "|" represents the rest of the rows within that collapse.
To cancel the left sidebar:
: Set foldcolumn&
You can use the mouse to click "+" in the folding bar to open a fold. Click "-", or a
' | ', an open collapse will be turned off.
Store and restore a collapsed:
When you close a file, do other things, or edit other files, come back to edit the same file later, if the folding is created manually, then all the folds are gone! In order to save the folds, you can use:
: Mkview
This will store settings and other content that affect the view of the file.
When you return to the same file later, you can reload the view:
: Loadview
You can store as many as 10 views for a file. For example, save the current setting as a third view and load the
Two views:
: Mkview 3
: Loadview 2
Dependent indent Folding:
If you want to rely on indentation folding, you first need to set
: Set Foldmethod=indent
If you write code comparison specifications, not the norm is OK, first select all, and then press "=", the code is a little more standardized. The complete command is ggvg=.
And then try ZM,ZR what the effect is, this feature is very useful for programmers. When we set the Foldmethod, we can no longer manually create the folding, for I like this feature does not like to be constrained in fact, it is not very good drop.
We just need to reset the Foldmethod.
: Set foldmethod& (the next & is to restore the default settings, which I understand anyway)
Other folding methods:
Dependency Identity Folding
Dependent syntax Folding
Dependency expression Folding
See also: http://vimcdoc.sourceforge.net/doc/usr_28.html#28.6
Reference: http://vimcdoc.sourceforge.net/doc/usr_28.html
Vim Folding Tips