是否有任何方法或工具可以在Vim中折叠函数,就像Visual Studio或Eclipse一样?
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.
zfgg
折叠从顶部到光标的所有行。
zfG
折叠从光标到底部的所有行。 - Christopher MarkietaShift+v
)中选择多行代码并使用zf
折叠它们。 - Christopher Markieta是的,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
让它们全部消失。
set nofoldenable
set foldlevel=99
这样可以禁用文件打开时的自动折叠,并且仅折叠外部函数(不会进入并折叠“for”、“if”等语句)。
尽管我的配置是基于你的回答,谢谢。 - merinofffoldlevel
大于20的设置没有影响,因为那是内部上限。 - Jamie S:set foldmethod=syntax
如果你有自己语言的语法文件,Sublime Text 应该会自动折叠所有函数和其他代码块。
Vim拥有出色的折叠支持。在vim帮助系统中有很好的文档。只需打开vim并执行以下操作:
:help usr_28.txt
读完这篇文章,你还可以阅读以下内容
:help folding
需要更多信息请参考。
是的,它绑定在“z”键上,例如zO打开所有折叠。请参阅Vim中的“:help fold”获取更多信息。您可以根据非常简单的规则(如缩进)或根据代码语法进行折叠。
&fold == syntax
或indent
原生提供的更好。 - Luc Hermitte