Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fold function in vim

Tags:

vim

folding

Is there any way or tools to fold function in vim, like Visual Studio or Eclipse?

like image 574
Yongwei Xing Avatar asked Mar 02 '10 12:03

Yongwei Xing


People also ask

What is fold in Vim?

Vim uses the same movement commands to define folds. Folding also works in visual mode. If you enter visual mode using v or V , then select a few lines of text using the movement keys, and type zf , Vim will create a fold comprising those lines. Another option is to specify a range in command mode.

How do I save a fold in Vim?

The problem is that when you close Vim, your artfully folded code returns to its unfolded state. The solution is quite simple - when you are ready to save your folds run the :mkview command. This will save your folds in the current buffer to your viewdir ( :h viewdir ) depending on your environment.

How do I expand all lines in Vim?

To expand the lines, put the cursor over the fold and hit spacebar (in vim terminology, this deletes the fold). (Side note: you may want to change the look of collapsed folds.

How do I unfold text in Vim?

Use zR to open all folds. The command zm gives more folding by closing one more level of folds throughout the whole buffer. Use zM to close all folds.


1 Answers

    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. 

Source: vim docs.

like image 62
codaddict Avatar answered Oct 23 '22 00:10

codaddict