Indentation
Indentation settings are configured for every programming language separately.
IntelliJ IDEA displays the indentation information in the status bar. So, if your project has files of different types, the easiest way of learning the current indentation style and accessing the corresponding settings is to use the Indentation widget.
Configure indentation style
In IntelliJ IDEA, you can configure indents in code style schemes or in .editorconfig files.
Open indentation settings in code style scheme
Click the widget and select Configure Indents for 'Language'.
In the dialog that opens, you can change settings for tabs and indents and also configure other code style settings. Click OK.
Reformat the necessary part of your project to apply new indentation settings.
Open indentation settings in .editorconfig
Files in which code style settings are specified via .editorconfig files have the icon in the widget.
Click the widget and select Open .editorconfig.
The IDE opens the nearest .editorconfig file which affects the file that you're currently working with. To view a list of all available .editorconfig files, click Show Files Related to Project.
Make your changes and reformat the necessary part of your project to apply new indentation settings.
Indentation settings for Java
Code style scheme settings are configured in
.Code style setting | EditorConfig property | Description |
---|---|---|
Use tab character |
| Use the tab or space character for indentation and code formatting. |
Smart tabs |
| When the option is on, the part of indentation defined by the nesting of code blocks is made of the tabs and (if necessary) spaces, while the part of indentation defined by the alignment is made only of spaces. When the option is off, a group of spaces that fits the specified tab size is automatically replaced with a tab, which may result in breaking fine alignment. |
Tab size |
| The number of spaces that a tab should include. |
Continuation indent |
| The number of spaces to be inserted between the elements of an array, in expressions, method declarations and method calls. |
Keep indents on empty lines |
| Keep indents on the empty lines as if they contained some code. Otherwise, IntelliJ IDEA will delete the tab characters and spaces. |
Label indent |
| The number of spaces to be inserted at the next line before a label statement. |
Absolute label indent |
| Count label indentation as an absolute number of spaces. Otherwise, label indentation is counted relative to previous indent levels. |
Do not indent top level class members |
| Place top-level class members at the class declaration indentation level. |
Use indents relative to expression start |
| Format blocks of code against the closest ancestor block that starts on a new line. Otherwise, blocks of code will be formatted in columns. |
Automatically detect indents
You can configure IntelliJ IDEA to detect the indentation style in the current file and use this style instead of the indents specified in the code style settings for a specific language.
Press Control+Alt+S to open the IDE settings and then select
.Select the Detect and use existing file indents for editing checkbox.
Click Apply to save the changes and close the dialog.
To disable automatic indentation, go back to settings and deselect the checkbox or click the Indentation widget and select Disable Indents Detection for Project.