When I click the plus sign, the code would automatically collapse.
Is there any plugin like this?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With