Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim Code Reading - Closing/Minimizing Brackets

Tags:

vim

perl

I have to read a few giant Perl scripts, and I would like to know how do you guys add the "minimizing" brackets functionality in Vim as GUI text editors do. I'm having a tough time understanding the code because of this, If I could just minimize those giant if, functions, etc... my mind would be very grateful.

like image 457
Jorge Sanchez Avatar asked Aug 03 '12 20:08

Jorge Sanchez


People also ask

How to enable folding in Vim?

Mappings to toggle folds With the following in your vimrc, you can toggle folds open/closed by pressing F9. In addition, if you have :set foldmethod=manual , you can visually select some lines, then press F9 to create a fold.

How to use folding 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 to delete a fold in Vim?

To delete all fold markers, visually select all the file with ggVG before doing a zd .

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.


1 Answers

By minimizing, I suppose you are referring to code "folding"

:help fold

zC closes all folds recursively under the cursor, zc closes a single fold. zo opens a single fold under the cursor, while zR recursively opens all folds.

See also

:help :foldmethod

For Perl, you will want :set foldmethod=syntax.

like image 105
Michael Berkowski Avatar answered Sep 27 '22 22:09

Michael Berkowski