Vim folding usage

Source: Internet
Author: User

 

Http://www.cnblogs.com/fakis/archive/2011/04/14/2016213.html1. Folding Mode

You can use the following options to set the folding mode:

Set OFDM = xxx in the vim configuration file
You can directly call the vim command/* VIM: Set OFDM = xxx: */using annotations in the file :*/

There are 6 Ways to select the fold:
1 manual definition folding
2. More indent indicates more advanced collapse.
3 expr use expressions to define collapse
4. Syntax uses syntax highlighting to define collapse
5 diff fold Unchanged text
6. Marker folds the mark in the text

Note that each folding method is incompatible. For example, you cannot use both expr and marker. I use indent and marker in turn.

In use, use the set OFDM = marker command to set it to the marker folding mode (OFDM is short for 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 canCodeWe need to fold the implementation. Because I use indent and marker a little more, we use them as an example: if indent is used, vim will automatically fold 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 ):
1 ZC fold
2 ZC fold all nested folding points in the range
3 Zo unfold and fold
4 Zo expands all nested folding points in the range
5 [Z to the start of the current fold.
6] Z to the end of the currently opened fold.
7 ZJ moves down. To the start of the next fold. The closed folding is also included.
8 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}. It is recommended that you do not change it.

We can use the following command to create and delete a fold:

01 ZF create a fold, for example, in the marker mode:
02 zf56g: Create Code folding from the current row to 56 lines;
03 10zf, 10zf +, or zf10 fold, create code folding from the current row to the last 10 lines.
04 10zf-or zf10 labels, create code folding from the current row to the previous 10 lines.
05 at ZF %, create the matching brackets (), {}, [], <>, etc.) from the current row ).
06
07 ZD Delete collapse under the cursor.
08 is valid only when 'foldmethod' is set to "Manual" or "marker.
09
10 ZD loop Delete: collapse under the cursor, that is, nested Delete fold.
11 valid only when 'foldmethod' is set to "Manual" or "marker.
12
13 ze remove all folds in the (eliminate) window.
14 is valid only when 'foldmethod' is set to "Manual" or "marker.

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

 

When we view long texts (for exampleProgramCode), you can use: Set foldenableCommand to start fold. First, fold the content according to its structure, view the outline of the file, and then fold the lines to be determined to display the detailed content of the text.

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

Usually move the cursor left or right at the fold, or enter the insert mode, the fold is automatically opened. You can also use the following command to define the shortcut key, use the space key to close the currently opened fold, or open the currently closed fold.

: Nnoremap <space> za

According to the folding rules, the indexes can be divided into manual (manual folding), indent folding, marker (TAG folding), and syntax (syntax folding.

Manual fold

Run the following command to enable manual folding.

: Set foldmethod = manual

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

ZF

You can combine the mobile command to collapse the specified line. For exampleZf70jCommand to collapse the 70 rows after the cursor. Use5zfCommand to fold the current line and the next four lines; UseZf7gCommand to fold the current line to the full text line 7th.

You can also use the following command to collapse the area surrounded by parentheses (such as (), [], {}, and> <:

Zfa (

Vim does not automatically fold the memory manually. However, you can use the following command to save the current folding status:

: Mkview

When you open the document next time, run the following command to load the folding information of the memory:

: Loadview

You can run the following command to view help information about manual folding:

: Help fold-Manual

Indent fold

Run the following command to enable indent collapse. All text will follow (OptionShiftwidthDefined) the indentation level is automatically folded.

: Set foldmethod = indent

UseZMCommands can be used to manually fold indentation.ZRTo open the collapsed indent.

Use the following command to fold indentation Based on the specified level:

: Set foldlevel = 1

You can run the following command to view the help information about indent collapse:

: Help fold-indent

Syntax fold

Run the following command to enable syntax collapse. All text is automatically folded according to the syntax structure.

: Set foldmethod = syntax

Run the following command to view help information about syntax collapse:

: Help fold-syntax

Marker fold

Run the following command to enable tag collapse. All text is automatically folded according to the specified tag (default: {{{and.

: Set foldmethod = marker

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

You can run the following command to view help information about tag collapse:

: Help fold-marker

Folding options

Use: Set foldcolumn = WCommand (WIs an integer between 0 and 12). A folding ID column is displayed on the left of the screen, indicating the folding of opening and closing with "-" and "+" respectively.

Run the following command to view the help information about collapse:

: Help folding

Command Summary
ZC Close the currently opened folding
Zo Open current fold
ZM Close all folds
ZM Close all folds and Their nested folds
ZR Open all folds
ZR Open all folds and nested folds
ZD Delete current collapse
Ze Delete all folds
ZJ Move to the next fold
ZK Move to fold
Zn Disable folding
Zn Enable 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.