JavaRush /Java Blog /Random EN /IntelliJ IDEA User Guide. Code style and formatting
theGrass
Level 24
Саратов

IntelliJ IDEA User Guide. Code style and formatting

Published in the Random EN group
IntelliJ IDEA User Guide.  Code style and formatting - 1

Code style and formatting

The code formatting standard determines the style of indentation, the use of spaces when formatting expressions, the method of placing parentheses delimiting logical blocks, empty lines, the order of operators, etc.
  1. Code Formatting

    IntelliJ IDEA automatically applies the code style you configure when editing, and in most cases you don't need to call Reformat Code explicitly. However, you can do this at any time for an entire file, just a selected piece of code, or even an entire directory by simply pressing Alt + Ctrl + L ( Alt + Cmd + L for Mac.)

    IntelliJ IDEA User Guide.  Code style and formatting - 2

    If you want to apply Reformat Code to all files in a directory, use the same button on the project toolbar.

    IntelliJ IDEA User Guide.  Code style and formatting - 3
  2. Automatic line alignment

    Another useful feature is Auto-Indent Lines , which helps you fix line indentation. This action is sometimes a better option than Reformat Code because it doesn't require you to select anything. Just press Alt + Ctrl + I (Alt + Cmd + I for Mac) and the current line will be indented quickly.

    IntelliJ IDEA User Guide.  Code style and formatting - 4
  3. Settings

    IntelliJ IDEA allows you to configure code style settings for each of the supported languages, either for a project or for the development environment as a whole using Settings → Code Style

    IntelliJ IDEA User Guide.  Code style and formatting - 5

    Style sheets for a project can be distributed to other members of your development team using version control.

  4. Tab character

    The last but not least important setting worth your attention is Use tab character. By default, this setting is disabled, and IntelliJ IDEA uses regular spaces to line lines instead of tab characters. If your files use too many spaces for code alignment, you can optimize their size by enabling this setting (4 spaces will be replaced by 1 tab character).

Original article
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION