2010-03-02 131 views
31

有什麼方法或工具可以在vim中摺疊功能,如Visual Studio或Eclipse?vim中的摺疊功能

此致

+0

如果你的意思是「自動摺疊類和功能」,那麼你應該明確地在你的問題澄清。 – 2010-03-02 12:10:10

+2

不是自動的,用戶可以選擇他想要摺疊的部分 – 2010-03-02 12:17:38

+0

vim有很好的文檔。試試:help fold – 2010-03-02 14:07:15

回答

84
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 docs。

+2

zc在光標處關閉摺疊。 (警告:通過實驗來計算) – Srikanth 2010-12-19 18:50:36

+4

za將切換摺疊(如果當前關閉則打開,反之亦然)。我覺得這很方便;幾乎從不使用zc或zo。 http://vim.wikia.com/wiki/Folding#Opening_and_closing_folds – Aman 2014-04-09 19:36:34

+1

'zfgg'摺疊從頂部到光標的所有行。 'zfG'摺疊從光標到底部的所有行。 – 2015-10-20 20:44:26

2

肯定的,它被綁定到 'Z' 鍵,例如zO打開所有摺疊。有關更多信息,請參閱vim中的「:help fold」。您可以根據非常簡單的規則進行摺疊,例如縮進或根據代碼語法。

10
:set foldmethod=syntax 

應該自動摺疊所有函數和其他塊,如果您有語言的語法文件。

3

Vim具有出色的摺疊支持。 vim幫助系統中有很好的文檔。只需打開VIM並做

:幫助usr_28.txt

閱讀,您也可以閱讀

後:幫助摺疊

一些更多的信息。

27

是的。 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 

,使他們都趕不走。

+1

這是最實際的答案,thks @bhekman – 2016-12-14 01:50:38

+2

我覺得有用的有: 'set nofoldenable' 'set foldlevel = 99' 也是。它禁用自動摺疊打開文件和摺疊只有外部功能(不加入和摺疊「fors」和「ifs」,什麼不是) 儘管我的配置基於你的答案,謝謝。 – merinoff 2017-07-06 16:43:54