Usage of VIM Folding

Source: Internet
Author: User

Http://www.cnblogs.com/fakis/archive/2011/04/14/2016213.html

1. Folding Mode

Available options to set the folding method:

Set fdm=xxx in the Vim configuration file
You can call the VIM command directly in the file using comments */* Vim:set fdm=xxx: */

There are 6 ways to select a fold:
1 manual hand-defined folding
2 indent more indents represent higher levels of folding
3 expr defines the collapse with an expression
4 syntax using syntax highlighting to define folding
5 diff collapses text that has no changes
6 marker to the logo folding in the text

Note that each folding method is incompatible, such as not both with expr and in the marker way, I mainly take turns using indent and marker way to fold.

When used, set the marker folding mode with 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 use them as an example: if you use the Indent method, Vim will automatically fold the middle part of the braces, We can use these ready-made folding results directly.

At the collapsible place (in the middle of the braces):
1 ZC Folding
2 ZC collapses all nested folding points within the range
3 Zo Expand fold
4 ZO for all nested folding points within the area
5 [Z to the beginning of the currently open folding.
6]z to the end of the currently open fold.
7 ZJ Move Down. arrives at the beginning of the next collapse. Closed folds are also counted.
8 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

We can use the following command to create and delete collapses:

The marker creates folds, such as in the form of a:
zf56g, creating a code folding from the current line to 56 lines;
10zf or 10zf+ or zf10↓, creating 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.
05 zf% in parentheses, creating the corresponding matching parentheses ((),{},[],<>, etc.) from the current line.
06
Zd deletion (delete) is collapsed under the cursor.
08 valid only if ' Foldmethod ' is set to ' manual ' or ' marker '.
09
The collapse of the ZD loop Delete (delete) cursor, which is nested delete collapse.
11 valid only if ' Foldmethod ' is set to ' manual ' or ' marker '.
12
ZE Remove the "all" folding in the (Eliminate) window.
14 valid only if ' Foldmethod ' is set to ' manual ' or ' marker '.


Http://yyq123.blogspot.com/2011/09/vim-fold.html

When we look at very long text (such as program code), you can use :set foldenable commands to start folding. You first collapse the content by its structure, view the outline of the file, and then expand the collapse for the row that is pending to display the details of the text.

Vim treats folding as rows-you can use the J or K commands to move the entire fold that contains multiple lines, or you can copy or delete a collapse using the Y or D command.

The cursor is usually moved to the left or right at the fold, or into insert mode, and the collapse is automatically opened. We can also use the following command to define a shortcut key, use the SPACEBAR to close the currently open fold, or open the currently closed fold.

:nnoremap <space> za

According to the rules of folding, can be divided into manual (manual folding), Indent (indentation folding), Marker (marker folding) and syntax (syntax folding) and several.

Manual Fold

Use the following command to enable manual folding.

:set foldmethod=manual

In visual mode, use the following command to collapse the selected text:

zf

By combining the move command, you can collapse the specified row. For example: Use the command to collapse zf70j 70 lines after the cursor, use the 5zF command to collapse the current line and the next 4 lines, and use the zf7G command to collapse the current line to the 7th line of the full text.

We can also use the following commands to collapse areas surrounded by parentheses (such as (), [], {}, ><, and so on):

zfa(

Vim does not automatically memorize manual folding. However, you can use the following command to save the current collapsed state:

:mkview

The next time you open the document, use the following command to load the collapsed information for the memory:

:loadview

You can use the following commands to view Help information about manual folding:

:help fold-manual

Indent Fold

Use the following command to enable indentation folding. All text is automatically collapsed according to the indentation level (as defined by option shiftwidth ).

:set foldmethod=indent

With zm commands, you can collapse indents manually, and you zr can open collapsed indents by using commands.

Use the following command to collapse the indentation according to the specified level:

:set foldlevel=1

You can use the following commands to view help information about indentation folding:

:help fold-indent

Syntax Fold

Use the following command to enable syntax folding. All text is automatically collapsed according to the syntax structure.

:set foldmethod=syntax

You can use the following commands to view Help information about syntax folding:

:help fold-syntax

Marker Fold--common

Use the following command to enable tag folding. All text is automatically collapsed according to a specific tag (the default is {{{and}}}).

:set foldmethod=marker

We can use tag folding to embody both structure and content in the text, and to quickly jump to different parts of the file.

You can use the following commands to view help information about tag folding:

:help fold-marker

Collapse options

Using the :set foldcolumn=W command (W is an integer of 0-12), a collapsed identity column is displayed on the left side of the screen, with "-" and "+" to represent open and closed folds.

Use the following command to view help information about folding:

:help folding

Command Summary
zc Close the currently open collapsed
zo Opens the current collapsed
zm Close all collapsed
zM Close all folds and their nested folds
zr Open all collapsed
zR Open all folds and their nested folds
zd Delete current collapse
zE Remove all collapsed
zj Move to next collapse
zk Move to the first fold
zn Disable Folding
zN Enable collapse

Usage of VIM Folding

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.