If you need to adjust indentation settings, in the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Editor | Code Style. On the appropriate language page, on the Tabs and Indents tab, specify the appropriate indents options and click OK.
Select the text you want to adjust. Go to Home and select Line and Paragraph Spacing > Line Spacing Options at the bottom of the menu. The Paragraph dialog box opens. On the Indents and Spacing tab, select the options you want, and click OK.
Press Ctrl+Alt+S to open the IDE settings and select Editor | Code Style. Select the Detect and use existing file indents for editing checkbox. Apply the changes and close the dialog.
Sometimes code formatting can get out of sync, but there's an easy fix in IntelliJ IDEA. You can use ⌘⌥L (macOS), or Ctrl+Alt+L (Windows/Linux) to reformat a selection of code according to your reformat settings.
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)
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
Select Java editor settings for Intellij Select values for Tabsize, Indent & Continuation Intent (I choose 4,4 & 4)
Then Ctrl + Alt + L to format your file (or your selection).
In Android Studio this works: Go to File->Settings->Editor->CodeStyle->Java. Under Wrapping and Braces uncheck "Comment at first Column" Then formatting shortcut will indent the comment lines as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With