65

是否有任何方法或工具可以在 vim 中折叠功能,如 Visual Studio 或 Eclipse?

4

5 回答 5

131
    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.

来源:vim 文档。

于 2010-03-02T12:07:33.760 回答
72

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

在我的 .vimrc 中:

set foldmethod=indent
set foldlevel=1
set foldclose=all

这会根据缩进自动折叠您打开的文件,以缩进超过 1 级的所有内容。foldclose 选项使折叠在我导航出折叠后自动重新关闭。

文件内控制:

zo - opens folds
zc - closes fold
zm - increases auto fold depth
zr - reduces auto fold depth

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

: set foldmethod=syntax

或按:

zR

让他们都走开。

于 2013-05-24T20:36:56.020 回答
25
:set foldmethod=syntax

如果你有你的语言的语法文件,应该自动折叠所有函数和其他块。

于 2010-03-02T12:11:14.390 回答
4

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

:help usr_28.txt 

看完之后你还可以阅读

:help folding

了解更多信息。

于 2010-03-02T14:20:22.057 回答
2

是的,它绑定到“z”键,例如 zO 打开所有折叠。更多信息参见 vim 中的 ":help fold"。您可以根据非常简单的规则(例如缩进)或根据代码语法进行折叠。

于 2010-03-02T12:04:29.023 回答