Folding Custom Regions with Line Comments
With IntelliJ IDEA, you can surround a fragment of source code with line comments. So doing, IntelliJ IDEA supports two styles:
- VisualStudio style
#region DescriptionYour code goes here...#endregion
- NetBeans style
// <editor-fold desc="Description">Your code goes here...// </editor-fold>
Do not mix up the two styles in one file. IntelliJ IDEA will recognize the first folding comment encountered, and will assume this as a style chosen for the code.
The folding markers of a region are stored with the source code and can be shared across the team.
To surround a custom region with folding markers
- Select a fragment of source code.
- On the main menu, choose Code | Surround With, or press Ctrl+Alt+T.
- Select the desired folding comments from the list:
IntelliJ IDEA surrounds the code fragment with comments observing the syntax of the current language.
- If necessary, change description of the code fragment to be folded:
You can now collapse or expand the code.
When collapsed, the code is concealed behind the description, and you can view it by hovering your mouse pointer over the description:
Once custom regions are defined, IntelliJ IDEA provides navigation between them.
To navigate between custom regions
- Do one of the following:
- On the main menu, choose Navigate | Custom Region.
- Press Ctrl+Alt+Period.
- In the dialog box that opens, select the target custom region, and click OK:
The caret rests at the comment line opening the region in question.