Vim Setup Code Folding

Source: Internet
Author: User

Vim Setup Code Folding

Today looked at someone else to write the program's source code, found to be written with Vim, the code is interesting to use vim to fold the code, at first I thought it was a plug-in, and later on the Internet to check, to draw the following use of skills.

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 2 3 4 5 6 . manual &nb sp;        hand-defined folding          . indent           more indents for higher levels of folding           . expr              defining folding with an expression           . syntax           using syntax highlighting to define folding           . diff                to collapse text that has no changes          . marker           the flags in the text collapse

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):

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.

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:

ZF creates folds, such as in marker mode:

          zf56g, creating 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% in parentheses, creating the corresponding matching parentheses ((),{},[],<>, etc.) from the current line.   zd      Remove (delete) folds under the cursor.           is only valid when ' Foldmethod ' is set to ' manual ' or ' marker '.   zd     Loop Delete (delete) under the cursor fold, that is, nested delete collapse.           is only valid when ' Foldmethod ' is set to ' manual ' or ' marker '.   ze      Remove the "all" folding in the (Eliminate) window.           is only valid when ' Foldmethod ' is set to ' manual ' or ' marker '.


Vim Setup Code 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.