You can reformat source code to meet the requirements of your code style. IntelliJ IDEA will lay out spacing, indents, keywords etc. Reformatting can apply to the selected text, entire file, or entire project.
It is also possible to apply reformatting to the parts of the source code only, using the formatting markers.
- On the main menu, choose or or . , or press
Reformat Code dialog box, specify the reformatting scope:
- The current file.
- Selected text.
- All files in the current directory, including or omitting subdirectories. You can also include optimizing imports, by selecting the Optimize imports check box, which is enabled for the current directory only.
- Click Run.
- At the beginning of the region, create a line comment ( or or or or or , or , or or or or or ), and then manually type the marker specified in the Formatter off field of General page.
- At the end of the region, create a line comment ( or or or or or , or , or or or or or ), and then manually type the marker specified in the Formatter on field of General page.
- Perform code reformatting, as described above.
You can create a live template to surround a block of code with formatter off/on markers.