0007 Vim Code Folding function

Source: Internet
Author: User

Question: How do I implement the code folding function in vim? Workaround: Use Vim's own shortcut keys and commands directly, you can achieve a powerful folding small test folding: 1:set fdm=marker in vim to execute the command 2 5G the cursor jumps to line 5th 3 zf10g Fold the 5th line to the 10th line of code, VIM will collapse at the beginning and end Automatically add three consecutive curly braces as Mark 4 ZR open all folding 5 ZM off all folding 6 ZE Remove all Folding tab 7 exit Vim window to open again, perform 2-6 steps. Can still be folded, but not marked. The collapsed information is lost when you reopen it. Folding Method: 1 Manual (not commonly used) The default folding method, such as the 7th step above that method, turn off vim folding will be lost. If you want to keep the information collapsed, run: Mkview command, restart after use: Loadview command reply. The cache file generated by this command is located in the ~/.vim/view folder. When you move or rename a file, the collapsed information is still lost. 2 indent (Common) indentation folding method, the same indentation in the code will be collapsed. 3 syntax (infrequently used) syntax highlighting is collapsed, the curly brace portion is folded in C + +, and some of the other format codes cannot be collapsed automatically. 4 marker (commonly used) marks the folding method, such as the method used in 1-6 above. Turning off VIM folding information is not lost, and is easy to control and annotate. 5 There are two different diff and expr, which I haven't used yet. Details: 1 Take marker as an example, you can run in vim: Set Fdm=marker to set the Collapse method settings. When folding the method, = There is no space on either side. You can also add the command to the ~/.VIMRC to enable Vim to load automatically. 2 in the use of small test folding 2 3 step folding, Vim will automatically add three consecutive curly braces as a marker, you can add an introduction before the opening curly braces, add a level number after curly braces, the level number cannot be 0. such as:/* Collapse Description {{{} 1*//*}}}*/3 level definitions are slightly more complex. In general coding, it is common to add tag folds to code that does not need to be modified. There is no need to grade the folds in the give. If you want to quickly collapse, switch to indent folding, which applies to any code that has indentation. Collapse Command: 1 ZF creates a fold that can be collapsed in the previous way, or it can be collapsed after the code is selected. 2 ZF creates a collapse on the current line. When you plan to collapse the code at the outset, you can use the command to create a pair of folding symbols and then fill in the contents. 3:5,10FO running this command in Vim will collapse the generation in 5-10 rowsCan be replaced by other numbers. 4 ZD Delete the folds under the cursor. 5 ZD Delete the folds under the cursor, as well as nested folds. 6 ZE Delete all folds within the window. Valid only if the manual and marker folding methods are available. Turn folding on and off: 1 zo The fold under the open cursor. 2 ZO folds under the open cursor, as well as nested folds. 3 ZC Closes the fold under the cursor. 4 ZC closes the folding under the cursor, as well as the nested folds. 5 za When the cursor is closed on the fold, open it. When you open the fold, close it. 6 za and za are similar, but are valid for both the current fold and its nested folds. 7 Zv Open the current cursor is collapsed, only open enough to collapse so that the cursor is located in the row is not collapsed. 8 ZR and ZM a layer of open folding and a layer of closed folding, these two commands will decrement and increment a variable called foldlevel. If you find ZM and ZR is not good, it is possible that you continuously press the ZR or ZM more times, as long as more than a few times to let Foldlevel back to normal state. Perform the following ZR and ZM can also directly let Foldlevel return to normal state. 9 ZR and ZM Open all folds, set Foldlevel to the highest level. Turn off all folds, set Foldlevel to 0. Move between folds: 1 [Z to the beginning of the current open collapse. If it is already at the beginning, move to the beginning of the collapse that contains the collapse. 2]z to the end of the current open fold. If it is at the end, move to the end of the fold that contains the fold. 3 ZJ Move the cursor to the beginning of the next fold. 4 ZK moves the cursor to the end of the previous fold. Reference: Run in vim: H folding command to view the collapsed help document.

0007 Vim Code Folding function

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.