IntelliJ IDEA 14.0.0 Web Help

Folding and Expanding Code Blocks

Code blocks have folding toggles on the right edge of the gutter next to each block. When a block is folded, the toggle foldingPlus appears to the left of the first line of the block. When a block is expanded, the toggle foldingMinusStart is shown at the beginning of the block and foldingMinusEnd at its end.

Folding and expanding code blocks works for entire classes, inner and anonymous classes, method bodies, import lists, comments, HTML and XML tags , closures and language injections.

You can fold (collapse) and unfold (expand) code blocks by using:

  • Code folding toggles (foldingMinusStart, foldingMinusEnd or foldingPlus). These toggles are shown in the editor on the left of the corresponding blocks. If a block is unfolded, foldingMinusStart indicates the beginning of the block while foldingMinusEnd is located at its end. For folded blocks, the toggle is shown as foldingPlus.
  • Commands of the Folding menu. The Folding menu can be accessed from the main menu bar ( Code | Folding ), or as a context menu in the editor.
  • Keyboard shortcuts. The corresponding shortcuts are shown in the Folding menu.

Folding menu

Item Shortcut Description
Expand Ctrl+NumPad+ Expand the current code block
Collapse Ctrl+NumPad - Collapse the current code block
Expand Recursively Ctrl+Alt+NumPad+ Expand all sub-blocks within the current code block
Collapse Recursively Ctrl+Alt+NumPad - Collapse all sub-blocks within the current code block
Expand All Ctrl+Shift+NumPad+ Expand all code blocks in the selected area, or in the current file if no area is selected
Collapse All Ctrl+Shift+NumPad - Collapse all code blocks in the selected area, or in the current file if no area is selected
Expand to level Ctrl+NumPad *, 1
Ctrl+NumPad *, 2
Ctrl+NumPad *, 3
Ctrl+NumPad *, 4
Ctrl+NumPad *, 5
Expand the selected code block to a certain level
Expand all to level Ctrl+Shift+NumPad *, 1
Ctrl+Shift+NumPad *, 2
Ctrl+Shift+NumPad *, 3
Ctrl+Shift+NumPad *, 4
Ctrl+Shift+NumPad *, 5
Expand all code blocks in the current file to a certain level
Expand doc comments N/A Expand all documentation comments in the current file
Collapse doc comments N/A Collapse all documentation comments in the current file
Fold Selection / Remove region Ctrl+Period Collapse the selected fragment / Expand the selected fragment and make it "unfoldable"
Fold Code Block Ctrl+Shift+Period Collapse the code between the nearest { and }

See Also

Reference:

Web Resources:

Last modified: 12 November 2014
comments powered by Disqus