Formatting

Formatting Code in IntelliJ IDEA.

We don’t read code like we do a piece of text, from start to finish. Code doesn’t run linearly! We scan the code to get a feel for the “shape” of the code, and to find the specific code we’re interested in.

IntelliJ IDEA will take care of formatting the code while we are writing code. If we encounter code that is not properly formatted, we can have IntelliJ IDEA reformat the code for us. In the file you want to reformat, use the shortcut ⌘⌥L (macOS) / Ctrl+Alt+L (Windows/Linux).

We can restructure the code by moving code blocks around to match our mental model, preferred style or coding conventions. Use ⌘⇧↑ (macOS) / Ctrl+Shift+Up Arrow (Windows/Linux) to move a statement up, or ⌘⇧↓ (macOS) / Ctrl+Shift+Down Arrow (Windows/Linux) to move a statement down.