IntelliJ IDEA 2021.3 Help

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.

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

  1. Click the widget and select Configure Indents for 'Language'.

    Configure Indents for Java
  2. In the dialog that opens, you can change settings for tabs and indents and also configure other code style settings. Click OK.

  3. 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 Platform impl ide config file icon in the widget.

  1. Click the widget and select Open Current File.

    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.

    EditorConfig menu opened from the Indentation widget
  2. 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 Settings/Preferences | Editor | Code Style | Java.

Code style setting

EditorConfig property

Description

Use tab character

indent_style = tab

indent_style = space

Use the tab or space character for indentation and code formatting.

Smart tabs

ij_smart_tabs = true

ij_smart_tabs = false

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

tab_width

The number of spaces that a tab should include.

Continuation indent

ij_continuation_indent_size

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

ij_java_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

ij_java_label_indent_size

The number of spaces to be inserted at the next line before a label statement.

Absolute label indent

ij_java_label_indent_absolute

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

ij_java_do_not_indent_top_level_class_members

Place top-level class members at the class declaration indentation level.

Use indents relative to expression start

ij_java_use_relative_indents

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.

  1. Press Ctrl+Alt+S to open the IDE settings and select Editor | Code Style.

  2. Select the Detect and use existing file indents for editing checkbox.

  3. Apply 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.

Last modified: 01 August 2022