Search code examples
intellij-ideaindentation

How to correct indentation in IntelliJ


How can indentation be automatically (not manually) corrected in IntelliJ?

In Eclipse, it's possible to just highlight the code that needs indenting, right-click, and select Source > Correct indentation.

Is there any method for doing the same thing in IntelliJ?


Solution

  • CodeReformat Code... (default Ctrl + Alt + L) for the whole file or CodeAuto-Indent Lines (default Ctrl + Alt + I) for the current line or selection.

    You can customise the settings for how code is auto-formatted under FileSettingsEditorCode Style.


    To ensure comments are also indented to the same level as the code, you can simply do as follows:

    UI screenshot (example for JavaScript)