How to correct indentation in IntelliJ

↘锁芯ラ 提交于 2019-11-28 16:26:35
CrazyCoder

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:

(example for JavaScript)

junaidp

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

Jim Van Zandt

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

Gapmeister66

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.

msingathi majola

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!