On this page:
- Code folding means
- Folding predefined and custom regions
- Commands of the Folding menu and associated shortcuts
- Specifying code folding preferences
- Viewing folded code fragments
- Using code folding comments
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 ().
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, i.e. 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 bar (), 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 to such elements as
import declarations, method bodies,
documentation comments, etc.
The predefined regions, roughly, correspond to the ones listed under Collapse by default
on the page in the
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 the Fold Selection/ Remove Region command (Ctrl+Period).
- Regions surrounded by corresponding commented folding markers
//<editor-fold desc="Description">...//</editor-fold>). See Using code folding comments.
Commands of the Folding menu and associated shortcuts
Specifying code folding preferences
You can specify:
- Whether the code folding toggles should be shown.
- Which folding regions should be collapsed by default.
For more information, see Code Folding page.
Viewing folded code fragments
To see the contents of a folded fragment, point to the ellipsis that indicates that fragment.
Viewing the beginning of a folding region
To see the beginning of a folding region - if it's not currently visible - point to the folding toggle at the end of that region.
Using code folding comments
Supported folding comments
You can create custom folding regions by surrounding code fragments with the following commented lines:
//<editor-fold desc="Description"> ... //</editor-fold>
Visual Studio style:
//region Description ... //endregion
Once you have chosen the style for a file, don't use the other style in that file.
Surrounding a fragment with folding comments
- Select the code fragment of interest.
- Select or press Ctrl+Alt+T.
- Select the folding comments to be used.
Specify the fragment description.
Now if you collapse the fragment, the description you have specified is shown in place of the code.
Navigating to folding regions
You can navigate to custom folding regions that were formed by surrounding code fragments with the corresponding commented folding markers:
- Select or press Ctrl+Alt+Period.
- Select the target folding region. (The regions in the list are identified by their descriptions.)