How to correct indentation in IntelliJ

2019-01-21 06:59发布

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?

6条回答
萌系小妹纸
2楼-- · 2019-01-21 07:38

You can also try out ctrl + alt + I even though you can also use l as well.

查看更多
看我几分像从前
3楼-- · 2019-01-21 07:39

Just select the code and

  • on Windows do Ctrl + Alt + L

  • on Linux do Ctrl + Windows Key + Alt + L

  • on Mac do CMD + Alt + L

查看更多
神经病院院长
4楼-- · 2019-01-21 07:43

Ctrl + Alt + L works with Android Studio under xfce4 on Linux. I see that Gnome used to use this shortcut for lock screen, but in Gnome 3 it was changed to Super+L (AKA Windows+L): https://wiki.gnome.org/Design/OS/KeyboardShortcuts

查看更多
Lonely孤独者°
5楼-- · 2019-01-21 07:45

Select Java editor settings for Intellij Settings Select values for Tabsize, Indent & Continuation Intent (I choose 4,4 & 4)

Then Ctrl + Alt + L to format your file (or your selection).

查看更多
时光不老,我们不散
6楼-- · 2019-01-21 07:50

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.

查看更多
Juvenile、少年°
7楼-- · 2019-01-21 07:58

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)

查看更多
登录 后发表回答