How enable auto-format code for Intellij IDEA?

后端 未结 15 1064
小鲜肉
小鲜肉 2020-12-22 17:05

Is it possible in Intellij IDEA after typing \';\' or press \'Enter\' happened formatting of this string?

For instance, to:

a+b=10;

相关标签:
15条回答
  • 2020-12-22 17:50

    File-> Settings -> Keymap-> Complete Current Statement

    I added ; key in there. When typing ';' at the end of the line, it is auto-formatting.

    UPDATE

    I realized that this will cause some problems in some situations. Use Ctrl+Shift+Enter instead. This key can be used in any position of cursor in a line. It will add ; at the end of the line. Also this shortcut have some other useful features.

    like:

    public void someMethod()
    

    after shortcut:

    public void someMethod() {
        // The cursor is here
    }
    

    so formatting on inserting ; is not necessary.

    0 讨论(0)
  • 2020-12-22 17:50

    Per the comment of Larson, this is now possible with the save-actions plugin.

    0 讨论(0)
  • 2020-12-22 17:54

    Eclipse has an option to format automatically when saving the file. There is no option for this in IntelliJ although you can configure a macro for the Ctrl+S (Cmd+S on Mac) keys to format the code and save it.

    Intellij reformat on file save

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