How enable auto-format code for Intellij IDEA?

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

    Ctrl+Shift+Enter combination (Complete Statement) also does the job and makes some more handy stuff with functions, cycles, etc.

    JetBrains docs: https://www.jetbrains.com/help/idea/2016.3/completing-statements.html

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

    Default one is Ctrl+Alt+L There is a key-mapping dialog box where you can configure/overwride all keyboard shortcuts.

    Navigate File->Settings->KeyMap

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

    I know this question is quite old but there is actually a Save Actions plugin for IntelliJ that can be configured to format the code automatically.

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

    The formatting shortcuts in Intellij IDEA are :

    • For Windows : Ctrl + Alt + L
    • For Ubuntu : Ctrl + Alt + Windows + L
    • For Mac : ⌥ (Option) + ⌘ (Command) + L
    0 讨论(0)
  • 2020-12-22 17:39

    In Mac it is Alt+Command+L(assuming you haven't changed any of your modifier keys or Intellij keyboard shortcuts from it's default state)

    0 讨论(0)
  • 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.

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