Fold and unfold (collapse/expand) code fragments
You can collapse (fold) code fragments to a single visible line, hiding the details that are unimportant at the moment. When necessary, folded code fragments can be unfolded (expanded).
Folded code fragments are shown as shaded ellipses ().
If the folded code block contains errors, the ellipses are displayed in red .
To see the contents of a folded block, hover over the folding ellipsis .
tip
To extend the editor area, you can hide all tool windows by pressing CtrlShiftF12 or by double-clicking the current editor tab, or you can hide all IDE elements in the Zen Mode by choosing View | Appearance | Toggle Zen mode from the menu.
Predefined regions that correspond to import declarations, method bodies, documentation comments, and so on.
You can fold and unfold predefined regions using the folding arrows on the gutter and dedicated keyboard shortcuts.
Any selected code fragment can be folded by pressing Ctrl0. or choosing Code | Folding | Fold Selection / Remove Region from the menu.
Use code folding arrows (
,
, and
) in the editor gutter.
tip
If you hold the Alt key and click the folding arrows, the code blocks are folded or unfolded recursively.
You can configure whether and how to show the folding arrows on the Editor | General | Code Folding settings page CtrlAlt0S.
Use the commands of the Folding menu and associated keyboard shortcuts.
Click
in the editor to unfold a folded block.
The Folding menu can be accessed from the main menu (Code | Folding), or as a context menu in the editor.
Command | Shortcut | Description |
---|---|---|
Collapse | CtrlNumPad - | Collapse the foldable block where your caret is.. |
Expand | CtrlNumPad + | Expand the collapsed block under the caret. |
Collapse Recursively | CtrlAltNumPad - | Collapse the current foldable block and all foldable blocks within it. |
Expand Recursively | CtrlAltNumPad + | Expand the collapsed block under the caret all the collapsed blocks within it. |
Expand All | CtrlShiftNumPad + | Expand all collapsed blocks in the document or within the selection. |
Collapse All | CtrlShiftNumPad - | Collapse all foldable blocks in the document or within the selection. |
Expand all to level | 1, 2, 3, 4 or 5 |
| Expand all the folded blocks in the document up to the specified nesting level. |
Collapse doc comments | Collapse all documentation comments in the current document. | |
Expand doc comments | Expand all documentation comments in the current document. | |
Fold Selection / Remove region | Ctrl0. | Collapse the selected fragment and create a custom folding region for it to make it 'foldable' or expand the current fragment and remove the corresponding custom folding region. |
note
The state of folded blocks is saved in the project settings and not in the file itself, therefore Undo Ctrl0Z and Redo CtrlShift0Z do not apply to actions that fold and unfold code blocks.
MPS allows you to configure:
Whether and how to show the code folding arrows.
Which folding regions should be collapsed by default.
You can change the corresponding settings on the Editor | General | Code Folding settings page CtrlAlt0S.
Thanks for your feedback!