vim中的折叠功能

Yon*_*ing 50 vim folding

有没有办法或工具来折叠vim中的函数,比如Visual Studio或Eclipse?

cod*_*ict 103

    Vim folding commands
---------------------------------
zf#j creates a fold from the cursor down # lines.
zf/ string creates a fold from the cursor to string .
zj moves the cursor to the next fold.
zk moves the cursor to the previous fold.
za toggle a fold at the cursor.
zo opens a fold at the cursor.
zO opens all folds at the cursor.
zc closes a fold under cursor. 
zm increases the foldlevel by one.
zM closes all open folds.
zr decreases the foldlevel by one.
zR decreases the foldlevel to zero -- all folds will be open.
zd deletes the fold at the cursor.
zE deletes all folds.
[z move to start of open fold.
]z move to end of open fold.
Run Code Online (Sandbox Code Playgroud)

资料来源:vim docs.

  • za将切换折叠(如果当前关闭则打开,反之亦然).我觉得很方便; 几乎从不使用zc或zo.http://vim.wikia.com/wiki/Folding#Opening_and_closing_folds (4认同)
  • zc在光标下关闭折叠.(警告:通过实验计算出来) (2认同)
  • zfgg将所有行从顶部折叠到光标。zfG将所有行从光标折叠到底部。 (2认同)
  • 您还可以在可视线模式(`Shift + v`)中选择多行并使用`zf`折叠它们. (2认同)

bhe*_*man 52

是.VIM具有出色的折叠功能.我不喜欢学习太多的控件,我更喜欢自动化,所以这是我个人使用的:

在我的.vimrc中:

set foldmethod=indent
set foldlevel=1
set foldclose=all
Run Code Online (Sandbox Code Playgroud)

这会自动折叠您打开的文件,基于缩进,对于缩进超过1级的所有内容.折叠关闭选项使折叠自动重新关闭.

文件内控件:

zo - opens folds
zc - closes fold
zm - increases auto fold depth
zr - reduces auto fold depth
Run Code Online (Sandbox Code Playgroud)

如果你对褶皱感到恼火,请使用

: set foldmethod=syntax
Run Code Online (Sandbox Code Playgroud)

或按:

zR
Run Code Online (Sandbox Code Playgroud)

让它们全部消失.

  • 我觉得有用:`set nofoldenable``set foldlevel = 99`.它禁用打开文件上的自动折叠并仅折叠外部功能(不踩进和折叠"fors"和"ifs"等等)根据你的答案制作我的配置,谢谢. (3认同)
  • 这是最实用的答案,thks @bhekman (2认同)
  • @merinoff 虽然它可能永远无关紧要,但根据文档(8.1 版),设置大于 20 的 `foldlevel` 没有任何影响,因为这是内部上限。 (2认同)

Pau*_*aul 18

:set foldmethod=syntax
Run Code Online (Sandbox Code Playgroud)

如果您的语言有语法文件,则应自动折叠所有函数和其他块.


Neg*_*_EV 6

Vim 具有出色的折叠支持。vim 帮助系统中有很好的文档。只需打开 vim 并执行以下操作

:help usr_28.txt 
Run Code Online (Sandbox Code Playgroud)

读完后您还可以阅读

:help folding
Run Code Online (Sandbox Code Playgroud)

了解更多信息。