Vim code folding

Source: Internet
Author: User

VimCodeFold
You can use the "foldmethod" option to set the vim code folding method, for example, set foldmethod = indent.

There are 6 Ways to collapse the code

1. Manual // manually define the folding
2. indent // fold with indentation
3. expr // use an expression to define the fold
4. Syntax // use syntax highlighting to define collapse
5. Diff // fold Unchanged text
6. Marker // hide with a flag

 

Vim configuration files are dividedGlobal configuration fileAndUser Configuration File

1. Search for the global configuration file. In. Vim, enter echo $ vim, which is generally/usr/share/Vim/vimrc.
2. the user configuration file is in the user's home directory, for example,/home/abeen/. vimrc.

Set the folding mode in the vimrc file, for example, set foldmethod = indent.

 

After the folding mode is selected, you can use the folding command to perform the folding operation. The common folding modes are indent and marker.

Indent folding command
Indent mode. Vim automatically uses indentation for folding. We can use the ready-made folding results.
Enter the following command in the fold:

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.

 

Marker folding command
When the marker folding method is used, we need to use a tag to identify the code folding. The default value is {And }}}
Fold command

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.

 

After 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.