Fold and unfold (collapse/expand) code fragments
You can collapse (fold) types, members, and other 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 .
![JetBrains Rider: Viewing the contents of a folded code block on mouse hover JetBrains Rider: Viewing the contents of a folded code block on mouse hover](https://resources.jetbrains.com/help/img/rider/2024.3/rdr_foldingPopup.png)
tip
To extend the editor area, you can hide all tool windows by pressing 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, types,
#region ... #endregion
blocks, documentation comments, keywords likeif
,while
,foreach
, 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 Ctrl0M,0H 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 | Ctrl0M,0S | Collapse the foldable block where your caret is.. |
Expand | Ctrl0M,0E | 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 | Ctrl0M,0X | Expand all collapsed blocks in the document or within the selection. |
Collapse All | Ctrl0M,0A | Collapse all foldable blocks in the document or within the selection. |
Collapse to Definitions | Ctrl0M,0O | Collapse all method defined in the current document and make only their signatures visible. |
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 | Ctrl0M,0H | 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 Ctrl0Y do not apply to actions that fold and unfold code blocks.
JetBrains Rider 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.