Ted's Blog

Happy coding

VIM设置代码折叠

Ted posted @ 2008年8月25日 20:55 in 未分类 with tags vim , 2844 阅读

在查看代码的时候,如果代码十分冗长,尤其是c/c++系列的时候,
代码结构比较让人难以理清,主要是各种注释、括号的匹配问题,
虽然可以用%来查看匹配的另外一半符号在哪里,但是如果这一对符号之间的代码超过了一页,甚至好几页的话,那么也是比较难以理解的。
于是可以使用这个vim所提供的折叠功能来简化这些分析。
我使用的vim是rh9自带的版本。
折叠的方式:

vim 提供 6中折叠方式
          manual           手工定义折叠
          indent             更多的缩进表示更高级别的折叠
          expr                用表达式来定义折叠
          syntax             用语法高亮来定义折叠
          diff                  对没有更改的文本进行折叠
          marker            对文中的标志折叠


可用选项 'foldmethod' 来设定折叠方式:set fdm=*****。
注意,每一种折叠方式不兼容,即:你不能用expr又用marker方式。
目前我一般使用的都是indent 比较多。
使用时,用:set fdm=indent 命令来设置成marker折叠方式。
在.vimrc文件中添加设置,可以使得每次打开vi 都启动折叠方式。如添加:set fdm=syntax。

2. 折叠打开与折合
选取了折叠方式后,我们就可以对某些代码实施我们需要的折叠了。

如果使用了indent方式,vim会自动的对大括号的中间部分进行折叠,我们可以直接使用这些现成的折叠成果。
indent 对应的折叠代码有:
zc      折叠
zC     对所在范围内所有嵌套的折叠点进行折叠
zo      展开折叠
zO     对所在范围内所有嵌套的折叠点展开
[z       到当前打开的折叠的开始处。
]z       到当前打开的折叠的末尾处。
zj       向下移动。到达下一个折叠的开始处。关闭的折叠也被计入。
zk      向上移动到前一折叠的结束处。关闭的折叠也被计入。

使用时在大括号中间输入以上命令。

当使用marker方式时,需要用标计来标识代码的折叠,系统默认是{{{和}}},最好不要改动之:)
可以使用下面的命令来创建和删除折叠:

zf      创建折叠,比如在marker方式下:
                   zf56G,创建从当前行起到56行的代码折叠;
                   10zf或10zf+或zf10↓,创建从当前行起到后10行的代码折叠。
                   10zf-或zf10↑,创建从当前行起到之前10行的代码折叠。
                   在括号处zf%,创建从当前行起到对应的匹配的括号上去((),{},[],<>等)。
zd      删除 (delete) 在光标下的折叠。仅当 'foldmethod' 设为 "manual" 或 "marker" 时有效。
zD     循环删除 (Delete) 光标下的折叠,即嵌套删除折叠。
          仅当 'foldmethod' 设为 "manual" 或 "marker" 时有效。
zE     除去 (Eliminate) 窗口里“所有”的折叠。
          仅当 'foldmethod' 设为 "manual" 或 "marker" 时有效。

Avatar_small
Navodaya Result 说:
2021年1月26日 23:11

The Result of Navodaya Vidyalaya will be declared in online mode. The candidate can check results by login to the official webs announced online, it has been announced in login and candidates can check it by entering registration number and date of birth. Merit list for the exam shall be available soon. Exam for JNVST class 6 was held on https://navodayaresults.in/ Navodaya Result Result 2021 Chhattisgarh January 11 and for class 9 it was conducted on February 08, 2020. The new date for phase 2 is yet to be announced and for class 11 admission the merit list will be released directly on the basis of qualifying marks score. Check more details on JNVST 2020 result from this page.

Avatar_small
Faddy 说:
2021年7月14日 20:40

Thanks for the tips guys. They were all great. I have been having issues with being fat both mentally and physically. Thanks to you guys i have been showing improvements. Do post more. elta 8 THC

Avatar_small
no excuses runner 说:
2021年7月19日 15:17

Common outings let us discuss simplest way to thanks a ton for your personal efforts, which will is why I'm just checking out the positioning on a daily basis, interested in innovative, helpful information and facts. Lots of, thanks a lot! astm level 3

Avatar_small
Faddy 说:
2021年9月11日 15:10

Impressive web site, Distinguished feedback that I can tackle. Im moving forward and may apply to my current job as a pet sitter, which is very enjoyable, but I need to additional expand. Regards. restaurants near me

Avatar_small
aспално бельо 说:
2021年9月16日 19:11

Nice to read your article! I am looking forward to sharing your adventures and experiences. https://www.storeholidayhours.org/

Avatar_small
aспално бельо 说:
2021年9月18日 03:52

Deutschlands Wrestling-Magazin seit 1995: WWE & AEW, dazu die gesamte Wrestling-Welt. News, Ergebnisse, Hintergründe, Podcasts und mehr. WWE Ergebnisse

Avatar_small
Faddy 说:
2021年9月19日 16:03

Efficiently written information. It will be profitable to anybody who utilizes it, counting me. Keep up the good work. For certain I will review out more posts day in and day out. https aka ms remoteconnect ps4

Avatar_small
Faddy 说:
2021年9月26日 16:13

Its a great pleasure reading your post.Its full of information I am looking for and I love to post a comment that "The content of your post is awesome" Great work. EMF Protectors

Avatar_small
aспално бельо 说:
2021年9月29日 01:32

Every security guard company has a goal of meeting and winning high-level clients. However, high-level clients are usually more demanding as compared to other clients. Such clients have past experience with the security companies, and they always look for the best. security guard services

Avatar_small
SEO 说:
2022年4月08日 04:09

After looking for the perfect doors for my renovation, I finally had it customized all thanks to Caldwells. Their ideas are unique and really worth the price. https://caldwells.com/ their site out for more information.

Avatar_small
dark web/deep web/d 说:
2022年8月04日 18:50

There is no header to indicate which domain or page is linked to. Each link is invisible until you click on it, making it impossible to track or scan for viruses or harmful software.   dark web links

Avatar_small
dark web/deep web/d 说:
2022年8月04日 19:34

There are many different reasons why these hackers choose to target websites that have a JavaScript code. One of the primary reasons is because these sites often contain many graphics that many users do not want to open.   deep web

Avatar_small
dark web/deep web/d 说:
2022年8月04日 19:50

Hackers can easily create new sites to steal your identity, and you could unknowingly become a victim of scams and other criminal activity. dark web links

Avatar_small
dark web/deep web/d 说:
2022年8月04日 20:12

I am sure that some of you are saying; well I know plenty of individuals who frequent the dark web, they are just normal users. Others argue that such links lead only to criminals, drug dealers, hackers, and identity thieves, well that's just not true. I know plenty of people who visit the dark web, and also live in cyberspace as well.   dark web sites

Avatar_small
dark web/deep web/d 说:
2022年8月04日 20:27

This way, you can get around the dangerous individuals and dangers that may pop up while you are looking at links. I use both the Mac interface and Windows interface to surf the net, and the privacy that you get with the VPN service is worth the price you pay.  dark web

Avatar_small
dark web/deep web/d 说:
2022年8月04日 20:42

The next thing that Chia teaches you in his course, and that you will find helpful in your own affiliate marketing business, is how to choose the right affiliate programs.   work from home jobs

Avatar_small
dark web/deep web/d 说:
2022年8月04日 20:58

One of the top affiliate marketing success stories of the year was Fathead, which launched an email series that targeted obese people looking to lose weight.   affiliate marketing success

Avatar_small
explain the principl 说:
2022年8月17日 20:07

The procedure is very well explained and appreciations for the writer who has put up so much effort in producing such unique and competitive content. The academic writers working for the platforms explain the principles for safe moving and handling are also skilled in delivering the unique and standard content.

Avatar_small
elisjohn 说:
2022年8月19日 12:58

The post and article is very well written and detailed. The delivery style of the writer is worth the appreciations and admiration. The content writers working for the entertainment platforms providing the [url=https://www.streamingdigitally.com/how-to-watch-house-of-the-dragon/]house of the dragon release date[/url] and other attractive movies and TV shows are also extremely reliable.

Avatar_small
elisjohn 说:
2022年8月19日 12:58

The post and article is very well written and detailed. The delivery style of the writer is worth the appreciations and admiration. The content writers working for the entertainment platforms providing the <a href="https://www.streamingdigitally.com/how-to-watch-house-of-the-dragon/">house of the dragon release date</a> and other attractive movies and TV shows are also extremely reliable.

Avatar_small
house of the dragon 说:
2022年8月19日 12:59

The post and article is very well written and detailed. The delivery style of the writer is worth the appreciations and admiration. The content writers working for the entertainment platforms providing the house of the dragon release date and other attractive movies and TV shows are also extremely reliable.

Avatar_small
ภูเก็ตแฟนตาซี 说:
2023年1月09日 04:11

Thank a lot. You have done excellent job. I enjoyed your blog . Nice efforts comments Phuket Package Tours

Avatar_small
buy testosterone cyp 说:
2023年3月10日 08:48

You completely match our expectation and the variety of our information. buy testosterone cypionate online

Avatar_small
logo embroidery digi 说:
2023年9月08日 19:31

wow, thanks for this information about the code folder This is very nice and very helpful and really interesting.

Avatar_small
logo embroidery digi 说:
2023年9月08日 19:33

wow, thanks for this information about the code folder This is very nice and very helpful and really interesting

Avatar_small
tech 说:
2023年12月06日 01:41

The next time I read a blog, I hope that it doesnt disappoint me as much as this one. I mean, I know it was my choice to read, but I actually thought you have something interesting to say. All I hear is a bunch of whining about something that you could fix if you werent too busy looking for attention. เซียนแทงบอลUFABET

Avatar_small
jsimitseo 说:
2024年1月31日 19:50

I suggest just great and dependable data, so observe it:  best concierge doctor

Avatar_small
SWWE 说:
2024年3月22日 16:22

Present a selection of SWWE's most notable projects, showcasing the diversity of styles, aesthetics, and design solutions they offer. Include before-and-after photos, renderings, or sketches to illustrate the transformative power of SWWE's design approach. Highlight key features of each project and the unique challenges they addressed.

Avatar_small
visaconsultant 说:
2024年3月22日 18:52

Discuss the partnerships and collaborations between IGL construction companies and local stakeholders in Pakistan. Highlight how these collaborations facilitate knowledge transfer, technology exchange, and capacity building within the local construction industry. Showcase examples of successful partnerships that have resulted in innovative and sustainable infrastructure solutions.

Avatar_small
chashmay 说:
2024年3月22日 19:07

Chashmay's women's sunglasses collection is a testament to the brand's commitment to trendsetting designs that blend fashion and functionality seamlessly. From oversized frames to sleek cat-eye shapes, Chashmay offers a variety of styles that cater to different tastes and preferences. Whether you prefer bold, statement-making sunglasses or subtle, understated elegance, you'll find a pair that complements your personal style effortlessly. <a href="https://www.chashmay.com.pk/">Sunglasses in Pakistan</a>

Avatar_small
shashkay 说:
2024年3月25日 16:51

At the heart of every pair of Shashkay Women sunglasses lies a commitment to craftsmanship excellence. Meticulously crafted using the finest materials, including premium acetate and lightweight metals, each frame undergoes rigorous quality checks to ensure impeccable construction and durability. From the precision of the hinges to the smooth finish of the frames, Shashkay's attention to detail sets a standard of excellence.

Avatar_small
digi ducks academy1 说:
2024年4月27日 23:14

At Digi Ducks Academy, we're dedicated to providing high-quality education that is accessible to all, which is why we offer online courses with certificate free. Join us and transform your future with Digi Ducks Academy's online courses today!

Avatar_small
digi ducks academy1 说:
2024年4月27日 23:14

At Digi Ducks Academy, we're dedicated to providing high-quality education that is accessible to all, which is why we offer online courses with certificate free. Join us and transform your future with Digi Ducks Academy's online courses today!

Avatar_small
weekly mag pro 说:
2024年7月19日 15:53

I think this is definitely an amazing project here. So much good will be coming from this project. The ideas and the work behind this will pay off so much.

Avatar_small
sultan 69 说:
2024年8月05日 15:41

Excellent .. Amazing .. I’ll bookmark your blog and take the feeds also…I’m happy to find so many useful info here in the post, we need work out more techniques in this regard, thanks for sharing. 

Avatar_small
best dogecoin casino 说:
2024年12月03日 19:36

I'm constantly searching on the internet for posts that will help me. Too much is clearly to learn about this. I believe you created good quality items in Functions also. Keep working, congrats!

Avatar_small
Finance Legend 说:
2024年12月16日 17:12

I have added and shared your site to my social media accounts to send people back to your site because I am sure they will find it extremely helpful too.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter