VIM Code Folding Vim code folding can be set using the "foldmethod" option, such as: Set Foldmethod=indent
There are 6 ways to fold code
1. Manual//manually define folding 2. Indent//With indentation for folding 3. Expr//Use an expression to define the folding 4. Syntax//Use syntax highlighting to define folding 5. Diff//collapse 6 for text that is not changed. Marker//Folding with logo
The vim configuration file is divided into global profile and user profile
1. Global profile lookup, input in. Vim: Echo $VIM, generally:/USR/SHARE/VIM/VIMRC 2. User profiles in the user's home directory, such as:/HOME/ABEEN/.VIMRC
Set the folding method in the VIMRC file: such as set foldmethod=indent
Once you have selected a folding method, you can use the collapse command to collapse the operation. The usual folding methods are indent and marker.
Indent folding Command indent way, VIM will automatically use indentation for folding, we can use ready-made folding results. We can enter the following command in the fold:
ZC Folding ZC Collapses all nested collapsed points within the range Zo expand collapse zo all nested collapsed points within the range expand [Z to the beginning of the currently open collapse. ]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.
Marker Folding Command marker folding mode, we need to use a tag to identify the collapse of the code, the system default is {{{and}}} collapse command
ZF creates folding, 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 next 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