How to correct indentation in IntelliJ
Just select the code and
on Windows do Ctrl + Alt + L
on Linux do Ctrl + Windows Key + Alt + L
on Mac do CMD + Option + L
Code
→ Reformat Code...
(default Ctrl + Alt + L) for the whole file or Code
→ Auto-Indent Lines
(default Ctrl + Alt + I) for the current line or selection.
You can customise the settings for how code is auto-formatted under File
→ Settings
→ Editor
→ Code Style
.
To ensure comments are also indented to the same level as the code, you can simply do as follows:
(example for JavaScript)