Ted's Blog

Happy coding

VIM设置代码折叠

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

在查看代码的时候,如果代码十分冗长,尤其是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


登录 *


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