PyCharm 4.0.0 Web Help

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, method bodies, import lists, comments, HTML and XML tags

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.

    Note

    If you hold the Alt modifier and click a toggle button in the gutter, the code block will be collapsed or expanded recursively, i.e. all sub-blocks within the parent block will also be collapsed or expanded.

  • 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+ or Ctrl+EqualsCtrl+NumPad+ or Ctrl+EqualsCtrl+NumPad+ or Ctrl+EqualsCtrl+NumPad+ or Ctrl+EqualsCtrl+NumPad+ or Ctrl+EqualsCtrl+NumPad+ or Ctrl+EqualsCtrl+NumPad+ or Ctrl+EqualsCtrl+NumPad+ or Ctrl+EqualsCommand NumPad or Command EqualsCommand NumPad or Command EqualsCommand NumPad or Command Equals Expand the current code block
Collapse Ctrl+NumPad - or Ctrl+MinusCtrl+NumPad - or Ctrl+MinusCtrl+NumPad - or Ctrl+MinusCtrl+NumPad - or Ctrl+MinusCtrl+NumPad - or Ctrl+MinusCtrl+NumPad - or Ctrl+MinusCtrl+NumPad - or Ctrl+MinusCtrl+NumPad - or Ctrl+MinusCommand NumPad - or Command MinusCommand NumPad - or Command MinusCommand NumPad - or Command Minus Collapse the current code block
Expand Recursively Ctrl+Alt+NumPad+ or Ctrl+Alt+EqualsCtrl+Alt+NumPad+ or Ctrl+Alt+EqualsCtrl+Alt+NumPad+ or Ctrl+Alt+EqualsCtrl+Alt+NumPad+ or Ctrl+Alt+EqualsCtrl+Alt+NumPad+ or Ctrl+Alt+EqualsCtrl+Alt+NumPad+ or Ctrl+Alt+EqualsCtrl+NumPad *Ctrl+Alt+NumPad+ or Ctrl+Alt+EqualsAlt Command NumPad or Alt Command EqualsAlt Command NumPad or Alt Command EqualsAlt Command NumPad or Alt Command Equals Expand all sub-blocks within the current code block
Collapse Recursively Ctrl+Alt+NumPad - or Ctrl+Alt+MinusCtrl+Alt+NumPad - or Ctrl+Alt+MinusCtrl+Alt+NumPad - or Ctrl+Alt+MinusCtrl+Alt+NumPad - or Ctrl+Alt+MinusCtrl+Alt+NumPad - or Ctrl+Alt+MinusCtrl+Alt+NumPad - or Ctrl+Alt+MinusCtrl+NumPad /Ctrl+Alt+NumPad - or Ctrl+Alt+MinusAlt Command NumPad - or Alt Command MinusAlt Command NumPad - or Alt Command MinusAlt Command NumPad - or Alt Command Minus Collapse all sub-blocks within the current code block
Expand All Ctrl+Shift+NumPad+ or Ctrl+Shift+EqualsCtrl+Shift+NumPad+ or Ctrl+Shift+EqualsCtrl+Shift+NumPad+ or Ctrl+Shift+EqualsCtrl+Shift+NumPad+ or Ctrl+Shift+EqualsCtrl+Shift+NumPad+ or Ctrl+Shift+EqualsCtrl+Shift+NumPad+ or Ctrl+Shift+EqualsCtrl+Shift+NumPad+ or Ctrl+Shift+EqualsCtrl+NumPad *Shift Command NumPad or Shift Command EqualsShift Command NumPad or Shift Command EqualsCommand NumPad * Expand all code blocks in the selected area, or in the current file if no area is selected
Collapse All Ctrl+Shift+NumPad - or Ctrl+Shift+MinusCtrl+Shift+NumPad - or Ctrl+Shift+MinusCtrl+Shift+NumPad - or Ctrl+Shift+MinusCtrl+Shift+NumPad - or Ctrl+Shift+MinusCtrl+Shift+NumPad - or Ctrl+Shift+MinusCtrl+Shift+NumPad - or Ctrl+Shift+MinusCtrl+Shift+NumPad - or Ctrl+Shift+MinusCtrl+Shift+NumPad /Shift Command NumPad - or Shift Command MinusShift Command NumPad - or Shift Command MinusShift Command 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 or Ctrl+NumPad *, NumPad-1Ctrl+NumPad *, 1 or Ctrl+NumPad *, NumPad-1Ctrl+NumPad *, 1 or Ctrl+NumPad *, NumPad-1Ctrl+NumPad *, 1 or Ctrl+NumPad *, NumPad-1Ctrl+NumPad *, 1 or Ctrl+NumPad *, NumPad-1Ctrl+NumPad *, 1 or Ctrl+NumPad *, NumPad-1Ctrl+NumPad *, 1 or Ctrl+NumPad *, NumPad-1Ctrl+NumPad *, 1 or Ctrl+NumPad *, NumPad-1Command NumPad *, 1 or Command NumPad *, NumPad-1Command NumPad *, 1 or Command NumPad *, NumPad-1Command NumPad *, 1 or Command NumPad *, NumPad-1
Ctrl+NumPad *, 2 or Ctrl+NumPad *, NumPad-2Ctrl+NumPad *, 2 or Ctrl+NumPad *, NumPad-2Ctrl+NumPad *, 2 or Ctrl+NumPad *, NumPad-2Ctrl+NumPad *, 2 or Ctrl+NumPad *, NumPad-2Ctrl+NumPad *, 2 or Ctrl+NumPad *, NumPad-2Ctrl+NumPad *, 2 or Ctrl+NumPad *, NumPad-2Ctrl+NumPad *, 2 or Ctrl+NumPad *, NumPad-2Ctrl+NumPad *, 2 or Ctrl+NumPad *, NumPad-2Command NumPad *, 2 or Command NumPad *, NumPad-2Command NumPad *, 2 or Command NumPad *, NumPad-2Command NumPad *, 2 or Command NumPad *, NumPad-2
Ctrl+NumPad *, 3 or Ctrl+NumPad *, NumPad-3Ctrl+NumPad *, 3 or Ctrl+NumPad *, NumPad-3Ctrl+NumPad *, 3 or Ctrl+NumPad *, NumPad-3Ctrl+NumPad *, 3 or Ctrl+NumPad *, NumPad-3Ctrl+NumPad *, 3 or Ctrl+NumPad *, NumPad-3Ctrl+NumPad *, 3 or Ctrl+NumPad *, NumPad-3Ctrl+NumPad *, 3 or Ctrl+NumPad *, NumPad-3Ctrl+NumPad *, 3 or Ctrl+NumPad *, NumPad-3Command NumPad *, 3 or Command NumPad *, NumPad-3Command NumPad *, 3 or Command NumPad *, NumPad-3Command NumPad *, 3 or Command NumPad *, NumPad-3
Ctrl+NumPad *, 4 or Ctrl+NumPad *, NumPad-4Ctrl+NumPad *, 4 or Ctrl+NumPad *, NumPad-4Ctrl+NumPad *, 4 or Ctrl+NumPad *, NumPad-4Ctrl+NumPad *, 4 or Ctrl+NumPad *, NumPad-4Ctrl+NumPad *, 4 or Ctrl+NumPad *, NumPad-4Ctrl+NumPad *, 4 or Ctrl+NumPad *, NumPad-4Ctrl+NumPad *, 4 or Ctrl+NumPad *, NumPad-4Ctrl+NumPad *, 4 or Ctrl+NumPad *, NumPad-4Command NumPad *, 4 or Command NumPad *, NumPad-4Command NumPad *, 4 or Command NumPad *, NumPad-4Command NumPad *, 4 or Command NumPad *, NumPad-4
Ctrl+NumPad *, 5 or Ctrl+NumPad *, NumPad-5Ctrl+NumPad *, 5 or Ctrl+NumPad *, NumPad-5Ctrl+NumPad *, 5 or Ctrl+NumPad *, NumPad-5Ctrl+NumPad *, 5 or Ctrl+NumPad *, NumPad-5Ctrl+NumPad *, 5 or Ctrl+NumPad *, NumPad-5Ctrl+NumPad *, 5 or Ctrl+NumPad *, NumPad-5Ctrl+NumPad *, 5 or Ctrl+NumPad *, NumPad-5Ctrl+NumPad *, 5 or Ctrl+NumPad *, NumPad-5Command NumPad *, 5 or Command NumPad *, NumPad-5Command NumPad *, 5 or Command NumPad *, NumPad-5Command NumPad *, 5 or Command NumPad *, NumPad-5
Expand the selected code block to a certain level
Expand all to level Ctrl+Shift+NumPad *, 1 or Ctrl+Shift+NumPad *, NumPad-1Ctrl+Shift+NumPad *, 1 or Ctrl+Shift+NumPad *, NumPad-1Ctrl+Shift+NumPad *, 1 or Ctrl+Shift+NumPad *, NumPad-1Ctrl+Shift+NumPad *, 1 or Ctrl+Shift+NumPad *, NumPad-1Ctrl+Shift+NumPad *, 1 or Ctrl+Shift+NumPad *, NumPad-1Ctrl+Shift+NumPad *, 1 or Ctrl+Shift+NumPad *, NumPad-1Ctrl+Shift+NumPad *, 1 or Ctrl+Shift+NumPad *, NumPad-1Ctrl+Shift+NumPad *, 1 or Ctrl+Shift+NumPad *, NumPad-1Alt Command NumPad *, 1 or Alt Command NumPad *, NumPad-1Alt Command NumPad *, 1 or Alt Command NumPad *, NumPad-1Alt Command NumPad *, 1 or Alt Command NumPad *, NumPad-1
Ctrl+Shift+NumPad *, 2 or Ctrl+Shift+NumPad *, NumPad-2Ctrl+Shift+NumPad *, 2 or Ctrl+Shift+NumPad *, NumPad-2Ctrl+Shift+NumPad *, 2 or Ctrl+Shift+NumPad *, NumPad-2Ctrl+Shift+NumPad *, 2 or Ctrl+Shift+NumPad *, NumPad-2Ctrl+Shift+NumPad *, 2 or Ctrl+Shift+NumPad *, NumPad-2Ctrl+Shift+NumPad *, 2 or Ctrl+Shift+NumPad *, NumPad-2Ctrl+Shift+NumPad *, 2 or Ctrl+Shift+NumPad *, NumPad-2Ctrl+Shift+NumPad *, 2 or Ctrl+Shift+NumPad *, NumPad-2Alt Command NumPad *, 2 or Alt Command NumPad *, NumPad-2Alt Command NumPad *, 2 or Alt Command NumPad *, NumPad-2Alt Command NumPad *, 2 or Alt Command NumPad *, NumPad-2
Ctrl+Shift+NumPad *, 3 or Ctrl+Shift+NumPad *, NumPad-3Ctrl+Shift+NumPad *, 3 or Ctrl+Shift+NumPad *, NumPad-3Ctrl+Shift+NumPad *, 3 or Ctrl+Shift+NumPad *, NumPad-3Ctrl+Shift+NumPad *, 3 or Ctrl+Shift+NumPad *, NumPad-3Ctrl+Shift+NumPad *, 3 or Ctrl+Shift+NumPad *, NumPad-3Ctrl+Shift+NumPad *, 3 or Ctrl+Shift+NumPad *, NumPad-3Ctrl+Shift+NumPad *, 3 or Ctrl+Shift+NumPad *, NumPad-3Ctrl+Shift+NumPad *, 3 or Ctrl+Shift+NumPad *, NumPad-3Alt Command NumPad *, 3 or Alt Command NumPad *, NumPad-3Alt Command NumPad *, 3 or Alt Command NumPad *, NumPad-3Alt Command NumPad *, 3 or Alt Command NumPad *, NumPad-3
Ctrl+Shift+NumPad *, 4 or Ctrl+Shift+NumPad *, NumPad-4Ctrl+Shift+NumPad *, 4 or Ctrl+Shift+NumPad *, NumPad-4Ctrl+Shift+NumPad *, 4 or Ctrl+Shift+NumPad *, NumPad-4Ctrl+Shift+NumPad *, 4 or Ctrl+Shift+NumPad *, NumPad-4Ctrl+Shift+NumPad *, 4 or Ctrl+Shift+NumPad *, NumPad-4Ctrl+Shift+NumPad *, 4 or Ctrl+Shift+NumPad *, NumPad-4Ctrl+Shift+NumPad *, 4 or Ctrl+Shift+NumPad *, NumPad-4Ctrl+Shift+NumPad *, 4 or Ctrl+Shift+NumPad *, NumPad-4Alt Command NumPad *, 4 or Alt Command NumPad *, NumPad-4Alt Command NumPad *, 4 or Alt Command NumPad *, NumPad-4Alt Command NumPad *, 4 or Alt Command NumPad *, NumPad-4
Ctrl+Shift+NumPad *, 5 or Ctrl+Shift+NumPad *, NumPad-5Ctrl+Shift+NumPad *, 5 or Ctrl+Shift+NumPad *, NumPad-5Ctrl+Shift+NumPad *, 5 or Ctrl+Shift+NumPad *, NumPad-5Ctrl+Shift+NumPad *, 5 or Ctrl+Shift+NumPad *, NumPad-5Ctrl+Shift+NumPad *, 5 or Ctrl+Shift+NumPad *, NumPad-5Ctrl+Shift+NumPad *, 5 or Ctrl+Shift+NumPad *, NumPad-5Ctrl+Shift+NumPad *, 5 or Ctrl+Shift+NumPad *, NumPad-5Ctrl+Shift+NumPad *, 5 or Ctrl+Shift+NumPad *, NumPad-5Alt Command NumPad *, 5 or Alt Command NumPad *, NumPad-5Alt Command NumPad *, 5 or Alt Command NumPad *, NumPad-5Alt Command NumPad *, 5 or Alt Command NumPad *, 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+PeriodCtrl+PeriodCtrl+PeriodCtrl+PeriodCtrl+PeriodCtrl+PeriodCtrl+PeriodCtrl+PeriodCommand PeriodCommand PeriodCommand Period Collapse the selected fragment / Expand the selected fragment and make it "unfoldable"

See Also

Reference:

Web Resources: