3

The title says most of it.

For the curious, folding is something I haven't yet included in my workflow. I use most of the time and I often have my hand on the mouse, scrolling through code.

Is there a way I can fold/unfold using the mouse?

Some IDE editors would have a + or - sign where unfolding/folding is possible.

Is there a way to add this to the GUI?

As with all things vim, I'm looking for a quick way to do it (least amount of clicks possible).

2

1 Answer 1

7

Credits to Ingo Karkat, you just need to set foldcolumn for using the mouse to open and close folds. From :he fold-foldcolumn:

FOLDCOLUMN                                              fold-foldcolumn

'foldcolumn' is a number, which sets the width for a column on the side of the
window to indicate folds.  When it is zero, there is no foldcolumn.  A normal
value is 4 or 5.  The minimal useful value is 2, although 1 still provides
some information.  The maximum is 12.

An open fold is indicated with a column that has a '-' at the top and '|'
characters below it.  This column stops where the open fold stops.  When folds
nest, the nested fold is one character right of the fold it's contained in.

A closed fold is indicated with a '+'.

Where the fold column is too narrow to display all nested folds, digits are
shown to indicate the nesting level.

The mouse can also be used to open and close folds by clicking in the
fold column:
- Click on a '+' to open the closed fold at this row.
- Click on any other non-blank character to close the open fold at this row.

Even though it says 2 is the minimal useful value, I'd say 1 is enough (:set foldcolumn=1):

enter image description here

Higher values make a better visual experience, but you still need to hit the + exactly.


On a side note, this section is the only instance of the word mouse in fold.text. (:he folding, /mouse)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.