212

What Xcode keyboard shortcuts do you use regularly?

I am a huge believer in using the keyboard as much as possible (its much faster that way), and I was hoping others could share some of the Xcode shortcuts they use.

7
  • 37
    A question upvoted 43 times is not constructive?
    – Boon
    Jan 22, 2014 at 20:13
  • 3
    How could this solicit anything but a list of commands?
    – Morkrom
    May 14, 2014 at 16:33
  • 3
    I put together a PDF of popular keyboard shortcuts: iphonedev.tv/blog/2014/9/25/…
    – Paul Solt
    Sep 26, 2014 at 5:08
  • 4
    I am surprised that none of the answers include [ctrl+6] for searching method or mark in the current file. Mar 2, 2015 at 19:42
  • 3
    Eurgh it annoys me so much how useful threads get closed by the SO police... Apr 2, 2016 at 4:10

16 Answers 16

253

I find the shortcuts to open & close various areas of the screen must useful.

shortcuts

11
  • Searched for this image in third time, finally saved, it's great. Always forget filters.
    – DanSkeel
    Nov 29, 2012 at 17:31
  • 4
    @DanSkeel Thank you. Quick note on the navigator filter - I used to frequently use cmd-option-j to filter then navigate to source files. However now I find the open quickly command better (cmd-shift-O , type a few chars, return)
    – Robert
    Nov 30, 2012 at 12:45
  • 6
    If you want to focus on search field of Search Navigator you can press Command + 3 and then hit Command + Option + j
    – DanSkeel
    Jun 2, 2013 at 9:58
  • 8
    A nice addition would be ^(1-6) for the UI elements above the main editing area. You can easily navigate to Recent Files, Callers, and the Method list. Note that you can start typing after any one of those. (Very useful with Control-6.)
    – funroll
    Jun 5, 2013 at 15:51
  • Does anyone know how to assign multiple Shortcuts to one action in the Xcode preferences? Some actions are pre-defined with multiple shortcuts, but I couldn't figure out how to, e.g. assign both PageUp and the default one for "Switch to next Counterpart".
    – Raffael
    Aug 8, 2013 at 19:43
138

Cmd + Shift + o opens the "Open quickly" dialog, where you can quickly find and open files that contain the text you enter.

6
  • 17
    Changed to Cmd-Shift+o in Xcode 4 Mar 15, 2011 at 18:01
  • 1
    Changed to CTRL-i in Xcode 4.5
    – Seunghoon
    Oct 20, 2012 at 20:34
  • 4
    Still Cmd-Shift+o in my Xcode 4.5.2 Nov 23, 2012 at 11:37
  • 3
    Appears to be CMD-Shift-o in Xcode 5 also.
    – livingtech
    Oct 8, 2013 at 19:51
  • 1
    Best shortcut of XCode period Nov 22, 2016 at 13:27
61

Updated for newer versions:

Control + Command +

Switches between corresponding .h / .m files or as Apple's own documentation, it means Jump to Counterpart

8
  • 2
    If you're on a .m file, it switches to the corresponding .h file, and vice versa. May 27, 2012 at 19:46
  • 28
    It's Control+Cmd+Up/Down on my version of Xcode (4.5.2) Nov 23, 2012 at 11:41
  • 3
    It's Control+CMD+Up/Down on Xcode 5.1
    – Faizan S.
    Apr 8, 2014 at 20:45
  • In Apple keyboard Control key called as Option.
    – ADJ
    May 21, 2014 at 4:21
  • 1
    @ArunPratap not correct. Option is option or alt, control is control
    – ff10
    Mar 21, 2016 at 16:45
47

command + shift + j

Reveals the current file in the project navigator. Very useful if you use command + control + J to jump to a definition as Xcode won't automatically reveal the containing file in the navigator.

1
  • 3
    love it! is super useful! Mar 27, 2015 at 11:17
42

command /

Comment out the current line, or multiple lines if they're highlighted.

Comes in handy for quick commenting and uncommenting while experimenting with code.

3
  • cmd + control + / too
    – evanhutomo
    May 4, 2014 at 23:39
  • 5
    Except uncomment doesn't bloody work half of the time.....
    – cacau
    May 20, 2014 at 9:11
  • 1
    Uncommenting only does not work when your selection contains one or more lines that are not already commented.
    – DarkByte
    Jun 19, 2014 at 8:03
27

Re-indent. It's in Edit > Format > Re-Indent and there's no shortcut by default (I use Command + Shift + L). It's a godsend.

5
  • 28
    There's also "Indent Selection", Control I.
    – Darren
    Sep 9, 2009 at 22:36
  • 6
    There is a default keyboard shortcut added now (Xcode 4) for Re-Indent. Use Control + I. And the item has been moved under Editor -> Structure -> Re-Indent. Oct 9, 2012 at 9:19
  • 5
    Also highlight some code, and press Command + [ or ] to indent your selection.
    – Matej
    Apr 14, 2013 at 16:49
  • 1
    Minor clarification, it's "Control + letter i" I got crazy trying to use | lol Jul 14, 2015 at 1:57
  • 1
    Happy News, I have developed a xCode plugin which Indent the source file when saving :-) github.com/ThilinaHewagama/AutoIndentWithSave Sep 15, 2015 at 9:37
25

command F Search in the File

option command F Search & Replace in the File

shift command F Search in the whole project

shift option command F Search & Replace in the whole project

Notice the pattern for easy memorizing.

4
  • 5
    After Search in Project, once the results are in the Navigator, how can you iterate through them without having to use the mouse? (I hate having to click on each result)
    – tothemario
    May 2, 2014 at 22:33
  • 2
    Additionally, you can use Cmd + E to put the current selection in find (in file), and Cmd + G to select/jump to the next occurrence (Cmd + Shift + G moves backwards). Works great for quick replaces too (Alternating Cmd + G and Cmd + V). Personally I also mapped Cmd + Option + E to find selection in project, for consistency with the above. Apr 11, 2015 at 6:50
  • @tothemario You can hit command-option-G to move to each project-level search result. shift-command-option-G will move back through each result. Apr 7, 2017 at 19:46
  • 1
    @tothemario currently it's Cmmd + Control + G for next & Cmmd + Control + Shift + G for previous. If you want the key combination then go to Preferences >> Key Bindings >> search for 'Find Next in Workspace' & Find Previous in Workspace'
    – mfaani
    Feb 18, 2019 at 22:04
20

Ctrl + Command + - Switch between header and implementation files.

1
  • You're making me cry!!! I didn't know that existed! Nov 1, 2013 at 23:53
14

Command + J (Move focus to any section of the editor)

2
  • 1
    What does this actually help us with?
    – Esqarrouth
    Apr 8, 2016 at 15:01
  • @Esqarrouth This shortcut can move the cursor from the assistant editor to the main editor, for example.
    – p-sun
    Nov 27, 2017 at 2:42
12

Control + Command + j

Highlight a keyword (method name) and jump to its definition. Also works for variables, #defines, etc.

2
  • 10
    Cmd + click on the symbol also works the same way.
    – Rakesh
    Jun 25, 2013 at 15:27
  • Add Option to the above shortcut to open the definition in your assistant editor.
    – yood
    Jun 30, 2014 at 14:14
7

Some of my favorite shortcuts are not keyboard shortcuts at all, but multitouch gestures. All Macbooks from early 2008 onward, and I would imagine desktops with a Magic Mouse or Magic Trackpad, support three-finger-swipe up and down to switch between the header and implementation, and three-finger-swipe left and right to navigate within the file history.

2
  • This doesnt work on my 2013 iMac with magic mouse, FYI, would be nice though! May 22, 2014 at 8:34
  • I use 3 finger left and right, but having up and down is perfect. Thanks. Mar 3, 2015 at 4:01
7

Command + Shift + Y for the console.

5
  • 2
    I think you mean Command-Shift-Y. That's what it is in Xcode 4.4.1.
    – arlomedia
    Sep 2, 2012 at 20:27
  • Yes, totally. Maybe it was Control back in Xcode 3 but it may also by a typo I made :) Sep 3, 2012 at 7:40
  • @arlomedia Using the shortcut only opens the console, but doesn't move your cursor to there. Is there anyway that I can make the cursor move up to there?
    – mfaani
    Nov 9, 2016 at 19:21
  • 1
    @Honey command+Shift+C Jan 3, 2017 at 12:20
  • @HaiFengKao thank you so much
    – mfaani
    Nov 27, 2018 at 19:18
6

I find a cheat sheet next to the computer is the best way to pick up useful shortcuts. Cocoa Samurai has a good one.

4

Key Bindings to XCode Actions

Create your own keyboard shortcuts using the Text Key Bindings tab of the Key Bindings preference pane. A time-saver all its own. Just lookup your favourite actions and add/edit shortcuts!

Another thread you may find useful is here.

3

Just the basic emacs navigation. Feels so right.

1

I cannot live without three finger vertical swipe to switch between interface and implementation file. If you miss that in xcode-4/Lion, make sure to follow the following instructions:

http://geeksinkilts.com/?p=67

3
  • 2
    alternatively, (for those looking for a keyboard shortcut) ctrl+cmd+up toggles between them, too
    – Ian Dundas
    Sep 14, 2015 at 14:03
  • Yeah, and much less of a hassle - wonder why you would want to move your hand to the trackpad when it's just a keyboard shortcut away..??
    – ATV
    May 6, 2016 at 4:59
  • If your hand is already on the trackpad, it's a nice option to have. May 9, 2016 at 20:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.