JetBrains Rider 2024.1 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 Ctrl+. or choosing Code | Folding | Fold Selection / Remove Region 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 settings  Ctrl+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

Ctrl+NumPad Minus

Collapse the foldable block where your caret is..

Expand

Ctrl+NumPad Plus

Expand the collapsed block under the caret.

Collapse Recursively

Ctrl+Alt+NumPad Minus

Collapse the current foldable block and all foldable blocks within it.

Expand Recursively

Ctrl+Alt+NumPad Plus

Expand the collapsed block under the caret all the collapsed blocks within it.

Expand All

Ctrl+Shift+NumPad Plus

Expand all collapsed blocks in the document or within the selection.

Collapse All

Ctrl+Shift+NumPad Minus

Collapse all foldable blocks in the document or within the selection.

Collapse to Definitions

Ctrl+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

  • Ctrl+Shift+NumPad *, 1

  • Ctrl+Shift+NumPad *, 2

  • Ctrl+Shift+NumPad *, 3

  • Ctrl+Shift+NumPad *, 4

  • Ctrl+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

Ctrl+.

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 settings  Ctrl+Alt+S.

Last modified: 28 June 2024