Vim code folding

Source: Internet
Author: User

In vim, I usually use visual mode to select some text and then use the ZF command to collapse the text. However, it is not very convenient to use visual mode, however, it is not very convenient to use it frequently. the command mode can be used: Start the row number, and end the row number folder command to fold,

You can use 110,120> to indent 110 rows to 120 rows.

Copy: 110,120 Yank to the default register

Or, copy 110,120 Yank X to the X register.

1. Folding Mode 
You can use the 'foldmethod' option to set the foldmethod: Set OFDM = *****.
There are 6 Ways to select the fold:
Manual manual definition folding
More indent indicates more fold
Expr uses expressions to define collapse
Syntax uses syntax highlighting to define collapse
Diff folds Unchanged text
Marker folds the mark in the text
Note that each folding method is incompatible. If expr is not used and marker is used, the indent and marker modes are used in turn.

When using this function, use the: Set OFDM = marker command to set it to the marker foldmethod ).
To make the folding take effect every time Vim is opened, add the settings in the. vimrc file, such as adding: Set OFDM = syntax, just like adding other initialization settings.

2. Fold command
After the folding method is selected, we can implement the folding we need for some code. Because I use more indent and marker, their usage is used as an example:
If the indent method is used, VIM automatically folds the middle part of the braces, and we can directly use these ready-made folding results.
In a foldable place (in the middle of braces ):
ZC folding
ZC folds all nested folding points in the range
Zo unfold and fold
Zo expands all nested folding points in the range
[Z to the start of the current fold.
] Z to the end of the currently opened fold.
ZJ moves down. To the start of the next fold. The closed folding is also included.
ZK moves up to the end of the previous fold. The closed folding is also included.

When using the marker method, you need to use a tag to identify code folding. The default value of the system is {And}. Do not change it :)
We can use the following command to create and delete a fold:
ZF creates a fold, for example, in the marker mode:
Zf56g: Creates code folding from the current row to 56 rows;
10zf, 10zf +, or zf10 labels, create code folding from the current row to the last 10 lines.
10zf-or zf10 labels, create code folding from the current row to the previous 10 lines.
At ZF %, create the matching brackets (), {}, [], <>, etc.) from the current row ).
ZD Delete is the folding of the cursor. Valid only when 'foldmethod' is set to "Manual" or "marker.
ZD loop Delete refers to the folding under the cursor, that is, nesting Delete fold.
Valid only when 'foldmethod' is set to "Manual" or "marker.
Ze removes all folds in the (eliminate) window.
Valid only when 'foldmethod' is set to "Manual" or "marker.

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.