Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any code-collapse-plugin of vim like this?

Tags:

vim

alt text When I click the plus sign, the code would automatically collapse.

Is there any plugin like this?

like image 377
Jichao Avatar asked Jan 17 '11 04:01

Jichao


2 Answers

It looks like you're looking for folding. Essentially all you need to get started is:

set foldmethod=syntax
set foldcolumn=<n>     " the number of columns to use for folding display at the left

and to manipulate it with the mouse, set mouse=a to turn on mouse stuff. The + and - to open/close folds appear in the foldcolumn at the left, next to the line numbers, not directly by the code as you've drawn, but it ought to be good enough! You'll probably want a column width of at least a couple, so you can see folds beyond the first level.

This does depend on folding having been defined for the syntax of the filetype you're currently editing. Vim comes with folding rules for some common things like C, but not everything. It's possible that if it's not shipped with vim, someone's created it, and you could find something suiting you out there.

like image 88
Cascabel Avatar answered Sep 17 '22 17:09

Cascabel


Setting foldcolumn to a number greater than 0 will put a + at the beginning of the line that you can click to fold or unfold blocks.

like image 22
Ignacio Vazquez-Abrams Avatar answered Sep 19 '22 17:09

Ignacio Vazquez-Abrams