Reputation: 23134
How can I fold an arbitrary block of code in intellij?
I know there is the cmd+. shortcut, but that only works if the selection is within a single line.
Upvotes: 1
Views: 1104
Reputation: 5224
Press Strg+A
(search for action) and search for Fold Selection
. My shortcut is Ctrl+.
. I don't know if this is the default short cut for that action.
This will fold your selection. If there is no selection, the surrounding code block will be folded.
Upvotes: 0
Reputation: 750
Cmd + '.'
, or on Windows Ctrl + '.'
shortcut indeed folds and unfolds selected block of code. If no code is selected, it folds the method in which the cursor is placed.
When you have cursor inside a method, you can fold/unfold entire method by Ctrl + '+'
/Ctrl + '-'
. The extensions of this combination are Ctrl + Shift + '+'
and Ctrl + Shift + '-'
, which fold/unfold all methods and comments in active file.
Upvotes: 6