Developers often spend most of their working hours on an IDE. If you’re an iOS, macOS, tvOS or watchOS developer, you’d probably be closer to your Xcode IDE than anything else at work.
I’ve often heard developers giving excuses to for not learning Xcode shortcuts when they’re starting out. In their defense, they have a valid argument:
If you don’t remember shortcuts, using a mouse at least helps you get work done quickly. Moreover, learning shortcuts feels like an additional learning curve especially when you’re getting started.
To shed some light on the impact keyboard shortcuts can have on a developer’s productivity, I’d share the findings of a study with them:
If your job requires you to be working with an IDE for eight hours a day, then using keyboard shortcuts can save you eight working days every year.
Eight days is a lot of time. By dedicating just a few hours a day, you can become proficient at using keyboard shortcuts in Xcode and save that extra week. Being productive with shortcuts would let you focus on bigger tasks at hand and speed up your development and workflow.
In the next few sections, we’ll walk through lots of Xcode keyboard shortcuts that I found useful. I hope they help you improve your efficiency as a developer too.
Here’s a list of the most common shortcuts used in Xcode:
Xcode 11 brought a lot of changes to their assistant editors. Now, you can add as many editors as you want, toggle focus mode on the current editor, or focuses on the current editor whilst hiding others. Additionally, a new button has been introduced that lets you set the position of the secondary editor relative to the current one.
The following shortcut lets you add secondary editor(s). The new editors aren’t reflected on your screen if you’re in focus mode.
Shortcut: ⌃ + ⌘ + T (Control + Command + T)
By hovering over the “Add New Editor” Button and holding the Option Key, we can toggle the position of the new editor to the right or bottom.
To hide all but the current editor, use the following set of keys:
Shortcut: ⇧ + ⌃ + ⌘ + ↩ (Shift + Control + Command + Enter)
One big change in the Xcode 11 Assistant Editor is that there is no manual option. In order to open a destination file in the secondary editor, do a Shift + Command + O todo a quick open, and press the option key while selecting the file, as shown:
Shortcut: ⇧ + ⌘ + O followed by ⌥
When working with multiple assistant editors and you need to switch between them, using the trackpad breaks the flow. Here are the shortcuts that let you deal with navigation across multiple editors:
Focus Current Editor: ⌘ + J (Command + J)
Once the editor gets highlighted you can navigation between the assistant editors with the arrow keys and press Return on the new editor to make it the active one.
I often come across scenarios where Xcode throws a lot of errors at me, specifically related to Swift syntax — which is common when you’re migrating across different versions.
Luckily the Fix-it All at once option works well for most of the general errors and saves us a lot of time, especially in huge projects.
( Control + Option + Command + F)
Often, there’s a need to use multiple cursors to avoid typing/copying the same thing on different lines. We can do that by selecting the current word and pressing Alt + Command + E to select the next occurrence(s). This places multiple cursors on the words and allows us to edit them together.
(Option + Command + E)
To select the previous occurrence, Shift + Option + Command + E is used.
Refactoring is inevitable. That makes editing variables and methods in the scope a crucial tool. The following shortcut lets us edit all in scope together at the same time:
( Control + Command + E)
In order to look at the outline of your file, the methods present, simply press Command + 6. It opens a jump bar from where you can search the desired method and you jump directly to it.
(Control + 6)
Since Xcode 9, command+click doesn’t directly take you to the definition. Instead, it shows you a pop-up hint with a list of options. In order to directly jump to the definition without seeing the pop-up use the following shortcut:
( Control + Command + J)
When your file sizes are going out of bounds (which ideally they shouldn’t) there’s a handy shortcut that lets you do code folding and collapse all methods/selective methods.
It puts a code ribbon on each enclosing block. Following are the shortcuts for the different cases:
(Shift + Option + Command + Left Arrow)
(Shift + Option + Command + Right Arrow)
(Option + Command + Left Arrow)
Xcode has a lot of shortcuts that let you choose the tab you want to close. It can be the current one or all but the current one. The shortcuts for each of the use cases are given below:
(Command + W)
(Command + Option + W)
To change the order of statements and to move them over one another the following shortcut is used:
(Command + Option + Square Brackets)
To quickly find the call hierarchy of the selected symbol, be it a method or an instance, just use the following shortcut. It opens the call hierarchy in the project navigator.
(Shift + Control + Command + H)
Xcode IDE has the ability to do a quick global search and even has the ability to replace the symbols everywhere (handle with care).
(Shift + Command + F)
(Shift + Command + Option + F)
SwiftUI has changed the way we think and build UIs. With a built-in canvas preview in Xcode, building UI through code or directly in the previews has just got a lot easier. The shortcuts are just the icing on the cake to speed up your development process.
If you’re looking to quickly build a prototype in code without letting the live previews distract you until its done, this is a handy shortcut.
(Option + Command + Enter)
Often the automatic preview pauses and requires us to manually resume it. Xcode 11 gladly has a shortcut for this.
(Option + Command + P)
Xcode 11 gave us minimaps. A much-needed outline view of your code on the right-hand side of the IDE. By hovering over it you can navigate to any part of your code.
Among the important shortcuts, one lets you toggle the minimap view while the other shows an outline of all the properties, methods, classes and blocks of code in the file:
(Shift + Control + Command + F)
(Shift + Control + Command)
We’ve had a quick tour through a lot of Xcode shortcuts that can increase your productivity and speed by leaps and bounds. Xcode 11 has introduced some handy utilities and shortcuts that should only help you accelerate your work.
For developers getting started with shortcuts, I’d recommend to take it slowly. Choose a few shortcuts and include them in your daily use cases to build up that muscle memory. Trying to memorize everything at once isn’t the optimal way to master keyboard shortcuts.
That’s it for this one — thanks for reading!