The formatting shortcuts in Intellij IDEA are :
- For Windows : Ctrl + Alt + L
- For Ubuntu : Ctrl + Alt + Windows + L
- For Mac : ⌥ (Option) + ⌘ (Command) + L
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.comIntellij-Plugin is overwriting Reformat-Code
Codestyle and formatters
Making auto format line up with IntelliJ formatting?
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.
Intellij finally implemented a feature that other IDEs had for years. You can now finally set up Intellij to automatically reformat your code and organize your imports on each save. There is no more need to either download the "Save Actions plugin" or to write your own macro to execute these two commands on each save. It was about effin' time.