How to correct indentation in IntelliJ

后端 未结 7 1546
逝去的感伤
逝去的感伤 2020-12-04 10:18

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, a

相关标签:
7条回答
  • 2020-12-04 10:56

    Solution of unchecking comment at first column is partially working, because it works for line comments, but not block comments.

    So, with lines like:

    /* first line
     * second line
     * ...
     */
    

    or

    // line 1
    // line 2
    // line 3
    ...
    

    they are indented with "Auto reformat", but lines like:

    /* first line
       second line
       ...
     */
    

    the identation will not be fixed.

    So you should:

    • add * or // before each line of comments
    • then uncheck Keep when reformatting -> comment at first column
    • and Auto reformat.
    0 讨论(0)
  • 2020-12-04 10:57

    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).

    0 讨论(0)
  • 2020-12-04 10:59

    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

    0 讨论(0)
  • 2020-12-04 11:03

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

    0 讨论(0)
  • 2020-12-04 11:06

    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)

    0 讨论(0)
  • 2020-12-04 11:15

    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

    0 讨论(0)
提交回复
热议问题