GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — note/note/vim/15折叠.md at master · trialbox/note

Expand file tree

/

15折叠.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
27 lines (20 loc) · 1.55 KB
/

15折叠.md

Copy path

File metadata and controls

27 lines (20 loc) · 1.55 KB
Raw
Copy raw file
Download raw file
Edit and raw actions

每日一Vim(15)折叠(fold)

抱歉,今天的文章可能写的很难懂,还请大家多多包涵。
写程序遇到大段的代码时,如果想像Eclipse一样把函数都折叠起来,只显示函数的签名,或者折叠一个函数中小段代码,这样一来,整个文件的代码结构一览无余,非常清晰,如果要查看函数里面的具体内容就打开,对程序员来说这是很实用的技巧。

Vim用命令foldmethod实现折叠功能,一共有六种折叠方式,可以用:set foldmethod查看当前session用的是哪种折叠,默认vim使用manual(手动)方式。

####manual 手工折叠是最基本的折叠方式,在处理小块文件的时候简单实用。

zf   创建折叠(fold creation)
zo   打开折叠(open)
zc   再次折叠起来(close)

举例说明:

v{motion}zf  折叠V模式下选中的文本。(这里的v{motion}指的是Shift+v)。
zf\`a    折叠当前光标处到标记a处的文本 (`ma`就表示在当前光标出做a标记)      
zf3j     折叠当前光标出下3行
zf10G    从当前行折叠至第20行
zfgg     折叠至行首
zf%      光标移至'{'时,vim会去匹配'}',这样'{}'之间的内容就可以折叠起来

####indent vim自动根据缩进折叠,缩进量与折叠行的嵌套深度关系有shiftwidth控制,通过设置:set foldlevel=num,num代表数字。foldlevel=0时关闭所有折叠,等价于zM,zR设置折行为最大值

You are visitor 01402894 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.