1. Folding Mode
The option ' Foldmethod ' can be used to set the folding mode: Set fdm=*****.
There are 6 ways to select a fold:
Manual manually defined Folding
Indent more indents represent higher levels of folding
Expr defines the collapse with an expression
Syntax to define folding with syntax highlighting
Diff collapses text that has no changes
Marker to the logo folding in the text
Note that each folding method is incompatible, such as the inability to use expr and the marker way, I mainly take turns using indent and marker way to fold.
When used, set the marker folding mode using the: Set fdm=marker command (FDM is the abbreviation for Foldmethod).
To enable the folding to take effect each time vim is turned on, add the settings in the. vimrc file, such as add: Set Fdm=syntax, just as you would add other initialization settings.
2. Collapse Commands
After choosing the folding mode, we can implement the folding we need for some code, because I use indent and marker a little more, so take their use as an example:
If the Indent method is used, Vim automatically collapses the middle part of the curly braces, and we can use these ready-made folding results directly.
At the collapsible place (in the middle of the braces):
ZC Folding
ZC folds all nested folding points within the range
Zo expand collapse
ZO for all nested folding points within the range
[Z to the beginning of the currently open collapsed.
]z to the end of the currently open fold.
The ZJ moves down. arrives at the beginning of the next collapse. Closed folds are also counted.
ZK moves up to the end of the previous fold. Closed folds are also counted.
When using the Marker method, you need to use a tag to identify the collapse of the code, the system default is {{{and}}, it is best not to change it:)
We can use the following command to create and delete collapses:
ZF creates folds, such as in marker mode:
ZF56G, creates a code folding from the current line to 56 lines;
10zf or 10zf+ or zf10↓, creates a code collapse from the current line to the following 10 lines.
10zf-or zf10↑, creates a code collapse from the current line to the previous 10 lines.
zf% at the parentheses, creating the corresponding matching parentheses ((),{},[],<>, etc.) from the current line.
ZD Remove (delete) is collapsed under the cursor. Valid only if ' Foldmethod ' is set to ' manual ' or ' marker '.
ZD Loop Delete (delete) is collapsed under the cursor, that is, nested delete collapses.
Valid only if ' Foldmethod ' is set to ' manual ' or ' marker '.
ZE Remove the "all" folding in the (Eliminate) window.
Valid only if ' Foldmethod ' is set to ' manual ' or ' marker '.
Vim Code Folding command