Fold code elements
You can collapse (fold) code fragments reducing them to a single visible line. In this way, you can hide the details that, at the moment, seem unimportant. If and when necessary, the folded code fragments can be expanded (unfolded).
Folded code fragments, normally, are shown as shaded ellipses ().
If the folded code block contains errors, JetBrains Rider highlights the folded fragment in red.
Code folding means
You can collapse and expand code fragments by using:
Code folding toggles (, or ). These toggles are shown in the editor to the left of the corresponding folding regions. If a region is unfolded, indicates the beginning of the region while is located at its end. For folded regions, the toggle is shown as .
If you hold the Alt key and click , or , the region is collapsed or expanded recursively, for example along with all its subordinate regions.
Commands of the Folding menu and associated keyboard shortcuts. The Folding menu can be accessed from the main menu ( ), or as a context menu in the editor. The shortcuts are shown right in the menu. See Commands of the Folding menu and associated shortcuts.
Folded fragments themselves: click to expand the corresponding fragment. See also, Viewing folded code fragments.
Folding predefined and custom regions
You can fold and unfold:
Predefined regions that correspond import declarations, method bodies, classes, documentation comments, etc. The predefined regions, roughly, correspond to the ones listed under Collapse by default on the Editor | General | Code Folding page of the IDE settings Ctrl+Alt+S.
For the predefined regions, the folding toggles are available right away, without the need to perform any additional actions.
Any selected code fragment. A custom folding region for a selection is created and removed by means of thecommand Ctrl+..
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.
Expand the current collapsed fragment.
Collapse the current folding region.
Expand the current folded fragment and all the subordinate collapsed folding regions within that fragment.
Collapse the current folding region and all the subordinate folding regions within it.
Expand all collapsed fragments within the selection, or, if nothing is selected, expand all the collapsed fragments in the current file.
Collapse all folding regions within the selection, or, if nothing is selected, collapse all the folding regions in the current file.
Expand to level | 1, 2, 3, 4 or 5
Expand the current fragment and all the nested fragments up to the specified level.
Expand all to level | 1, 2, 3, 4 or 5
Expand all the collapsed fragments in the file up to the specified nesting level.
Expand doc comments
Expand all documentation comments in the current file.
Collapse doc comments
Collapse all documentation comments in the current file.
Fold Selection / Remove region
Collapse the selected fragment and create a custom folding region for it to make it "foldable" / Expand the current fragment and remove the corresponding custom folding region to make the fragment "unfoldable".
Specifying code folding preferences
You can specify:
Whether the code folding toggles should be shown.
Which folding regions should be collapsed by default.
The corresponding settings are on the Editor | General | Code Folding page of the IDE settings Ctrl+Alt+S.
Viewing folded code fragments
To see the contents of a folded fragment, point to the ellipsis that indicates that fragment.