How enable auto-format code for Intellij IDEA?

后端 未结 15 1080
小鲜肉
小鲜肉 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:41

    You can do this with Save Actions plugin Refer This article on how to configure the plugin.

    Save Actions plugin Supports configurable, Eclipse like, save actions, including "optimize imports", "reformat code", "rearrange code", "compile file" and some quick fixes for Java like "add / remove 'this' qualifier", etc. The plugin executes the configured actions when the file is synchronised (or saved) on disk.

    1. Install the plugin
    2. Go to Settings > Other settings > Save actions
    3. Tick Activate save actions on save
    4. Tick Reformat file
    5. Apply > OK

    I prefer the hot-keys though, For Mac,

    To format the code : Ctrl+Alt(Option)+L

    And additionally I do,: Ctrl+Alt(Option)+O , This will remove unused imports and format the import list as well.

提交回复
热议问题