Vim code folding: Set the default code to not folding

Source: Internet
Author: User

Sometimes the code is too long to look at, especially when reading the source code, you need to fold the code that you don't care about first to look at the code that you are most concerned about. Vim comes with the code folding function.

Foldmethod can be configured to define the folding mode. There are 6 optional methods: 1. Manual // manually define the folding mode.
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 // I use syntax to define the folding with the flag. This method is relatively simple, but after this value is configured, open the code, vim collapsed all the code by default. This is obviously not what I want. After Google retries, find a solution. After setting foldlevelstart to 99, It is not collapsed by default. Configuration:
"Use syntax to highlight and define code folding
Set foldmethod = syntax
"Opening a file does not collapse the code by default.
Set foldlevelstart = 99
 


After the configuration is complete, you can enter the fold command on the method, class, if-Else, and various iterators on the desired block. Here, the simplest fold command is provided: ZC close fold Zo Open fold za open/close fold switch each other complete configuration of my code fold:

Set foldenable
Set foldmethod = Syntax "set syntax collapse
Set foldcolumn = 0 "set the width of the collapsed area
Setlocal foldlevel = 1 "set the number of folding layers
Set foldlevelstart = 99 "the Code is not folded by default when the file is opened.

"Set foldclose = all" is set to auto-disable fold
Nnoremap <space >@= (foldclosed (line ('.') <0 )? 'Zc': 'Z') <CR>
"Use the Space key to switch and collapse

 

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.