Formatting keyboard shortcut in Xcode

Xcode can format your entire file with a single key bind. Here’s how.

Short answer: ⌘ + A then press ⇧ + I
OR format the entire file with ⌃ + ⇧ + I

Sometimes when you write code and you play together with the editor, using tab suggestions and working a bit speedier, you end up with code that looks and feels ugly. Code that is malformatted might be compiled just fine, but it gets hard to read very fast.

Bildschirmfoto 2025-09-25 um 18.04.12.png

Manually formatting your code is an option, but also gets tedious fast.

That’s why nearly every major IDE has a code formatting feature that is waiting for you behind a keyboard shortcut.

Xcode is no exception to this rule.

In Xcode, you don’t have to format the entire codebase or the entire file like in other editors.

Here, it can work precisely on the text you’ve selected.

So you could select a block you want to be auto-formatted, or if you want to format the whole file, just select the entire content of the file with:

⌘ + A

And then you can auto-format by using:

⌃ + ⇧ + I

Bildschirmfoto 2025-09-25 um 18.04.40.png

Or to format the entire file, just press:
⌃ + ⇧ + I

That’s it!

As you can see by some work in progress SwiftUI from my upcoming app Charon, the auto-format has made the code block much, much more readable.

Thank you for reading and happy formatting!


Update History

Defined key binds more precisely

Added differentiation between complete file formatting and reformatting of selected lines.

Changed shortcut description to reflect update in Xcode

It seems the shortcut binding has updated to include the ⇧-Key

Published this article

To my knowledge... this article is published... effective immediately!

Created new article titled 'Formatting keyboard shortcut in Xcode'

Drafted the article and prepared for publishing.