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 .
What to fold and unfold
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 Control+. or choosing
from the menu.
How to fold and unfold
Use code folding arrows (, , and ) in the editor gutter.
You can configure whether and how to show the folding arrows on the Editor | General | Code Folding page of the IDE settings Control+Alt+S.
Use the commands of the Folding menu and associated keyboard shortcuts.
Click in the editor to unfold a folded block.
Commands of the Folding menu and associated shortcuts
The Folding menu can be accessed from the main menu ( ), or as a context menu in the editor.
Command | Shortcut | Description |
---|---|---|
Collapse | Control+NumPad-- | Collapse the foldable block where your caret is.. |
Expand | Control+NumPad-+ | Expand the collapsed block under the caret. |
Collapse Recursively | Control+Alt+NumPad-- | Collapse the current foldable block and all foldable blocks within it. |
Expand Recursively | Control+Alt+NumPad-+ | Expand the collapsed block under the caret all the collapsed blocks within it. |
Expand All | Control+Shift+NumPad-+ | Expand all collapsed blocks in the document or within the selection. |
Collapse All | Control+Shift+NumPad-- | Collapse all foldable blocks in the document or within the selection. |
Collapse to Definitions | Control+G, D | 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 | Control+. | 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. |
Configure code folding preferences
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 page of the IDE settings Control+Alt+S.