Code formatting shortcuts in Android Studio for Operation Systems
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Android Studio inherits most of its editor behavior from IntelliJ IDEA, so its code formatting shortcuts are consistent across JetBrains-style keymaps. The most important shortcuts are for reformatting code, optimizing imports, and invoking the full cleanup dialog, and the exact key combination depends on whether you are on Windows, Linux, or macOS.
The main reformat shortcut
The most-used action is "Reformat Code."
Shortcuts:
- Windows and Linux:
Ctrl + Alt + L - macOS:
Cmd + Option + L
This reformats the current file or the selected region according to the project's code style settings.
For example, if you select a block in a Kotlin file and press the shortcut, Android Studio reformats only that selection. If nothing is selected, it reformats the whole file.
That makes it the fastest daily cleanup tool for indentation, spacing, and wrapping.
Optimize imports separately
Unused imports and messy import ordering are handled by a different action:
- Windows and Linux:
Ctrl + Alt + O - macOS:
Cmd + Option + O
This removes unused imports and reorders the remaining ones according to the IDE settings.
Because import cleanup is separate from basic formatting, many developers either run both shortcuts or use the broader cleanup dialog when preparing code to commit.
Use the full cleanup dialog for more control
Android Studio also provides a richer dialog that can combine actions such as reformatting and rearranging:
- Windows and Linux:
Ctrl + Alt + Shift + L - macOS:
Cmd + Option + Shift + L
This is useful when you want to choose options such as:
- reformat code
- optimize imports
- rearrange code entries
- limit the action to changed lines
That last option is especially helpful in teams where you want minimal diff noise and do not want to reformat untouched parts of a large legacy file.
Formatting depends on code style settings
The shortcut does not apply some universal Android style by magic. It uses the project's current code style settings.
That means if the team has customized:
- continuation indent
- import ordering
- wrapping rules
- Kotlin or Java style conventions
the formatting shortcut will enforce those settings, not some default style from the internet.
So if formatting looks "wrong," the issue may be the project's code-style configuration rather than the shortcut itself.
A practical workflow
A productive Android Studio cleanup sequence is often:
- write or paste code
- reformat the file or selection
- optimize imports
- inspect the diff before committing
In many teams, the full cleanup dialog is used before commit, while the basic reformat shortcut is used constantly during normal editing.
This keeps formatting predictable without making every save operation feel heavy or intrusive.
Common Pitfalls
The biggest mistake is assuming the same keymap applies everywhere. If you use a custom keymap, or if the IDE imported a non-default scheme, the shortcuts may differ from the defaults.
Another mistake is expecting reformatting to fix logic errors or lint issues. Formatting changes layout and style, not program correctness.
Developers also confuse "optimize imports" with "reformat code." These are related but separate actions.
Finally, do not forget that formatting output depends on the project's code style settings. If the result is surprising, inspect the configuration instead of blaming the shortcut.
Summary
- The main reformat shortcut is
Ctrl + Alt + Lon Windows and Linux, andCmd + Option + Lon macOS. - Import cleanup uses
Ctrl + Alt + OorCmd + Option + O. - The full cleanup dialog is
Ctrl + Alt + Shift + LorCmd + Option + Shift + L. - Formatting follows the project's configured code style, not an abstract default.
- In practice, reformat code and optimize imports are the Android Studio shortcuts you will use most often.

