The formatting shortcuts in Intellij IDEA are :
- For Windows : Ctrl + Alt + L
- For Ubuntu : Ctrl + Alt + Windows + L
- For Mac : ⌥ (Option) + ⌘ (Command) + L
The formatting shortcuts in Intellij IDEA are :
- For Windows : Ctrl + Alt + L
- For Ubuntu : Ctrl + Alt + Windows + L
- For Mac : ⌥ (Option) + ⌘ (Command) + L
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.
- Install the plugin
- Go to Settings > Other settings > Save actions
- Tick Activate save actions on save
- Tick Reformat file
- 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.
What are your most popular keyboard shortcuts in IntelliJIDEA?
Reformat code via keyboard shortcut doesn't work in IntelliJ - Stack Overflow
Intellij finally has a built in "Reformat code and organize imports" save action in 2021.2
It automatically saves, so usually I just use the reformat code shortcut (rather than using save and have auto format in other IDEs)
More on reddit.comEssential IntelliJ Shortcuts
My favorite is ALT + J for select next occurrence. Multicursor is crazy useful. Once you get good with arrowkeys + modifiers and home/end it makes creating/editing stuff with the same pattern much easier.
More on reddit.comI am using Windows 10, default keyboard shortcuts setting. The most frequently used keyboard shortcuts are as follows:
-
CTRL+D for duplicating current line;
-
CTRL+ALT+O for optimizing imports;
-
CTRL+ALT+L for formatting code;
-
CTRL+Y for deleting current line;
The following magics are also useful:
-
.var
-
.sout
-
.if
-
.for
-
.foreach
-
.null
-
.nn
Check that your keyboard shortcuts are configured. To do this, press Ctrl+Alt+S, navigate to Keymap, open up Main menu drop down, open Code folder and check that Reformat Code has a key combination set. You can also find Reformat Code via the search bar.
Shortcut for formatting the code is (SHIFT + CTRL + ALT + L)