JetBrains Rider 2023.2 Help

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 (JetBrains Rider: Folded code block in the editor).

If the folded code block contains errors, the ellipses are displayed in red (JetBrains Rider: Folded code block that contains errors) .

To see the contents of a folded block, hover over the folding ellipsis JetBrains Rider: Folded code block in the editor.

JetBrains Rider: Viewing the contents of a folded code block on mouse hover

What to fold and unfold

  • Predefined regions that correspond to import declarations, method bodies, types, #region ... #endregion blocks, documentation comments, keywords like if, 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 Code | Folding | Fold Selection / Remove Region from the menu.

How to fold and unfold

  • Use code folding arrows (App client expui gutter fold, App client expui gutter fold bottom, and App client expui gutter unfold) 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 folded fragment 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 (Code | Folding), 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

  • Control+Shift+NumPad-*, 1

  • Control+Shift+NumPad-*, 2

  • Control+Shift+NumPad-*, 3

  • Control+Shift+NumPad-*, 4

  • Control+Shift+NumPad-*, 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.

Last modified: 01 September 2023