338

With a huge influx of newbies to Xcode, I'm sure there are lots of Xcode tips and tricks to be shared.

What are yours?

casperOne
  • 73,706
  • 19
  • 184
  • 253
schwa
  • 11,962
  • 14
  • 43
  • 54

89 Answers89

343

Switch to Header/Source File

  • Option ⌥ Command ⌘ Up Arrow ↑

  • View > Switch to Header/Source File

Switches between the .m and .h files.

  • In Xcode 4 this is ctrl Command ⌘ Up Arrow ↑
Community
  • 1
  • 1
epatel
  • 45,805
  • 17
  • 110
  • 144
  • 7
    This is absolutely my favorite, too. I use it constantly. Also works when we are talking about cpp and h. Not just m! :) – pestophagous Sep 30 '08 at 21:20
  • 24
    It's called "option" on the Mac, not "alt". And if you want fancy symbols, it can be written ⌥⌘↑ – Brian Campbell Mar 31 '09 at 15:33
  • 2
    Better yet, open the header, ⌘⌥⇡ to open the .m in the same window, then ⌘⌥⇠/⇢ to switch between them. – Peter Hosey May 08 '09 at 19:56
  • Slightly offtopic, but how do I get Firefox to show those funky symbols? Are they Unicode? Strange because I can see everything from Chinese to Thai to Arabic but not a Mac propeller symbol. – SPWorley May 13 '09 at 17:38
  • Tried Firefox and I see the ⌘-symbol here. I'm on a Mac so that might be a needed?!? When I look what encoding is used I see UTF-8 here too – epatel May 13 '09 at 19:05
  • ⌘⌥⇠/⇢ walks thru all displayable files in the project, including images. So cool. – willc2 Jun 28 '09 at 05:12
  • 4
    Note that in Xcode 3.2, you have to change the key bindings to restore ⌘⌥⇠/⇢ to switch-file. They changed the default to move between positions in the same file. – Peter Hosey Sep 14 '09 at 12:34
  • 71
    A three finger swipe up on the touchpad is another shortcut for the same action. – Nathan Dec 30 '09 at 02:07
  • @SPWorley: You need fonts that support the "Miscellaneous Technical" block, 2300–23FF. I don't know which ones that would be on non-OSX platforms (on OSX it's a pretty common symbol…) – Donal Fellows May 03 '10 at 08:01
  • You can also do three finger swipe-up to switch between .m and .h – zakishaheen Jul 01 '10 at 14:44
  • 2
    It's Ctrl + Cmd + ⇡ in XCode 4. – Mugunth Nov 30 '10 at 09:14
  • Bound this on my Logitech mouse, now that's productivity. – Vojto Jan 26 '11 at 07:09
  • I never use this command because I use mouse to click instead. Anyway,thx for sharing. – Chanok Jun 01 '11 at 16:31
  • three finger swipe will not work anymore in Xcode like it used to once you switch to OSX 10.7. The OS shows the desktops. – finneycanhelp Aug 25 '11 at 16:19
  • I have this shortcut mapped to the two finger swipe up in my magic mouse. Highly recomendable. – Bruno Berisso Oct 05 '11 at 12:52
  • Does anyone know of a way to get back / forwards in the same file in XCode 4? This was an awesome feature for jumping around in the same file and it looks like they just removed it for XCode 4 :( – glenc Jan 20 '12 at 02:43
158

⌘ Command + Double-Click on a symbol: Jump to Definition of a symbol.

⌥ Option + Double-Click on a symbol: Find Text in Documentation of a symbol. (Only works if you have they symbol's Doc Set installed.)

Favorites Bar:

Favorites bar is just like you have in Safari for storing - well - favorites. I often use it as a place to store shortcuts (which you can do by drag-dropping) to files I am using right now. Generally this is more useful when I'm working with a large or unfamiliar project.

To show the Favorites Bar, select the following menu option:

  • View > Layout > Show Favorites Bar
hbn
  • 1,846
  • 2
  • 12
  • 12
schwa
  • 11,962
  • 14
  • 43
  • 54
127

Auto-completion Keyboard Shortcuts

Tab ⇥ OR Control ⌃ /: Select the next auto-completion argument.

Shift ⇧ Tab ⇥ OR Shift ⇧ Control ⌃ /: Select the previous auto-completion argument.

Escape ⎋: Shows the auto completion pop-up list.

Senseful
  • 86,719
  • 67
  • 308
  • 465
mmalc
  • 8,201
  • 3
  • 39
  • 39
119

Turn off the "undo past the last point" warning

When you attempt to undo after saving, you will get the following prompt:

"You are about to undo past the last point this file was saved. Do you want to do this?"

To get rid of this warning, enter the following into a terminal window:

defaults write com.apple.Xcode XCShowUndoPastSaveWarning NO

Change the company name in template files

Paste this into the Terminal application:

defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{"ORGANIZATIONNAME" = "Microsoft";}'

Change "com.yourcompanyname" in all your templates:

  1. Find the directory: /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project Templates/Application
  2. Use your favourite multi-file search-and-replace tool to change com.yourcompany to whatever value you normally use to build for a device. I used BBEdit's multi-find-and-replace after I opened the whole directory. You should be replacing the value in all the info.plist files. I found 8 files to change. The number of times a build has failed because I forgot to change this string is ridiculous.

Quickly jump to a Group in the Groups and Files pane

  • Control ⌃ Option ⌥ Shift ⇧ + <First letter of a Group name>

If you hold down the three keys above, you can quickly jump to groups in the left (Groups and Files) page by pressing the first letter of a groups name. For example, Control ⌃Option ⌥Shift ⇧T takes you to Targets and Control ⌃Option ⌥Shift ⇧S to Source. Press it again and it jumps to SCM. Sometimes it takes several tries for this to work (I don't know why).


Cycling between autocompletion choices

  • Control ⌃ .

  • Shift ⇧ Control ⌃ .: Cycles backwards between autocompletion choices.

Control ⌃. (Control-Period) after a word automatically accepts the first choice from the autocompletion menu. Try typing log then Control ⌃. and you'll get a nice NSLog statement. Press it again to cycle through any choices. To see all the mutable choices, type NSMu then Control ⌃..


Quick Help

  • Control ⌃ Command ⌘ ? (While your cursor is in the symbol to look up)

  • Option ⌥ + <Double-click a symbol>

  • Help > Quick Help

To get to the documentation from the Quick Help window, click the book icon on the top right.


See the documentation for a symbol

  • Command ⌘ Option ⌥ + <Double-click a symbol>

Takes you straight to the full documentation.


Make non-adjacent text selections

  • Command ⌘ Control ⌃ + <Double-click in the editor>

Use the above shortcut for a strange way of selecting multiple words. You can make selections of words in totally different places, then delete or copy them all at once. Not sure if this is useful. It's Xcode only as far as I can tell.


Use Emacs key bindings to navigate through your code

This trick works in all Cocoa application on the Mac (TextEdit, Mail, etc.) and is possibly one of the most useful things to know.

  • Command ⌘ Left Arrow or Command ⌘ Right Arrow Takes you to the beginning and end of a line.
  • Control ^ a and Control ^ e Do the same thing
  • Control ^ n and Control ^ p Move the cursor up or down one line.
  • Control ^ f and Control ^ b Move the cursor back or forward one space

Pressing Shift ⇧ with any of these selects the text between move points. Put the cursor in the middle of a line and press Shift ⇧ Control ^ e and you can select to the end of the line.

Pressing Option ⌥ will let you navigate words with the keyboard. Option ⌥ Control ^ f skips to the end of the current word. Option ⌥ Control ^ b skips to the beginning of the current word. You can also use Option ⌥ with the left and right arrow keys to move one-word-at-a-time.

  • Control ^ Left Arrow and Control ^ Right Arrow moves the cursor between camel-cased parts of a word.

Try it with NSMutableArray. You can quickly change it to NSArray by putting your cursor after the NS, pressing Shift ⇧ Control ^ Right Arrow then Delete.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
nevan king
  • 112,709
  • 45
  • 203
  • 241
  • Thanks, I hate that "Are you sure..." message. Why is it even there in the first place? – ruipacheco Oct 22 '09 at 21:49
  • 4
    Control-Command-double-click is just necessary because Xcode uses Command-double-click for something else other than a discontiguous word selection. In most Cocoa apps you can do discontiguous selection with the Command modifier alone. – Nicholas Riley Nov 01 '09 at 01:26
  • About the template company name: XCode takes that out of your address card from AddressBook, so if you change it there, XCode will use it. – dertoni Dec 22 '10 at 09:32
  • You can also change the company name by setting one for yourself on your Address Book card. – macserv Feb 03 '12 at 22:54
99

Open Quickly...

  • Command ⌘ Shift ⇧ D

  • File > Open Quickly...

I'm a big fan of the Open Quickly feature, which is particularly good in Xcode 3.1 and later. When you want to open a file or a symbol definition that's in your project or in a framework, just hit the keyboard shortcut, type a bit of the file or symbol's name, use Up Arrow ↑ and Down Arrow ↓ to pick to the right result (if need be), and then hit Return ↩ to open the file or navigate to the symbol definition.

On Xcode 4:

  • Command ⌘ Shift ⇧ o

Open Quickly uses the current word as a search term

Also, something I didn't know about Xcode until two minutes ago (when schwa pointed it out in a comment) is that, if the editor's text caret is inside of a word when Open Quickly is invoked, that word will be used as the Open Quickly search term.

Community
  • 1
  • 1
Evan DiBiase
  • 1,104
  • 9
  • 16
  • Yeah Open Quickly works really well now. Also you can just put the text caret on the file of a #include/#import line and open that file quickly. – schwa Sep 28 '08 at 20:31
  • what are these "text caret" you guys talking about?? – ivanTheTerrible Mar 16 '09 at 20:52
  • The text caret is just the vertical bar inside of an area of text that indicates where your keyboard actions would take place. – Evan DiBiase Mar 20 '09 at 05:29
  • 9
    On the Mac, a "cursor" indicates your mouse position; the flashing vertical bar is the "insertion point". – Nicholas Riley Nov 01 '09 at 01:22
  • 1
    @Nicholas Riley: Caret is the right word, AFAIK - our mac developers always called it that when I worked in a software company – Polsonby May 09 '10 at 19:17
  • 3
    @Flubba: Caret is certainly *used* for this, I don't dispute it at all; it's just not the common user- or developer-centric term on Macs. If you Google for "caret site:developer.apple.com" you'll just find hits in TrueType documentation and in a single, very recently written, iPad document. – Nicholas Riley May 09 '10 at 21:32
  • @Nicholas Riley: Actually Cursor is correct, your mouse pointer is the "mouse cursor" which is a derative of the "regular" cursor (think about non-mouse machines) – alexanderpas Jun 18 '10 at 00:13
  • *Open Quickly is barely better than nothing*. Its biggest flaw is that it only does exact matching and only from beginning of file name. After recently finding a presentation called [Mastering Xcode 3](http://blog.libinpan.com/2010/06/mastering-xcode-3/), I now use [Code Pilot](http://macoscope.net/en/mac/codepilot/) which is far superior to Open Quickly. Check out the screencast on the Code Pilot site. Goodbye ⇧⌘D, hello ⇧⌘X. – Dave Lee Nov 16 '10 at 20:20
  • Thanks @DaveLee, I'm checking out Code Pilot now. – Dan Rosenstark Feb 05 '12 at 19:11
78

Use #pragma for organization

You can use:

#pragma mark Foo

... as a way to organize methods in your source files. When browsing symbols via the pop up menu, whatever you place in Foo will appear bold in the list.

To display a separator (i.e. horizontal line), use:

#pragma mark -

It's very useful, especially for grouping together delegate methods or other groups of methods.

Senseful
  • 86,719
  • 67
  • 308
  • 465
Steve Streza
  • 253
  • 2
  • 5
  • 9
    typing # p will usually trigger code completion '#pragma mark – willc2 Jun 28 '09 at 05:22
  • 1
    It also grabs `# TODO` statements. Now if only it would also grab `# XXX`, which is commonly used in the code base I work on... – asmeurer Dec 28 '10 at 06:22
  • 7
    Xcode 4 also supports "#pragma mark - Foo" which adds the mark AND a separator at the same time. – typeoneerror Aug 04 '11 at 00:07
77

1. Breakpoint on "objc_exception_throw"

You should always have a breakpoint on objc_exception_throw.

2. Debugging retain/release problems with "Zombie" variables

Use the following code:

NSZombieEnabled = YES;
NSDeallocateZombies = NO;

... to debug retain and release problems. For more information, see the "Finding Memory Leaks" section of Apple's Debugging Applications document.

3. Jumping to a class in Xcode from Interface Builder

Command ⌘ + Double-click on an object in Interface Builder's Document Window to jump to that class in Xcode. This is very handy with File's Owner.

4. Reusing customized objects in Interface Builder

Drag a customized object back to Interface Builder's Library for later reuse.

5. Select overlapping items in Interface Builder

Control ⌃ Shift ⇧ + Click on an object in Interface Builder to see a menu of all of the objects under the mouse.

6. Interface Builder Gesture Guide

Interface Builder Gesture Guide.

Community
  • 1
  • 1
Jon Hess
  • 14,237
  • 1
  • 47
  • 51
75

Ctrl + 2: Access the popup list of methods and symbols in the current file.

This is super useful because with this shortcut you can navigate through a file entirely using the keyboard. When you get to the list, start typing characters and the list will type-select to the symbol you are looking for.

ingh.am
  • 25,981
  • 43
  • 130
  • 177
mgorbach
  • 46
  • 1
  • 2
74

Zoom Editor In

If your window displays both the detail and editor view, you can zoom the editor in to expand the editor view to the full height of the window. (This is fairly easily found, but many seem to overlook it.)

You can do this by using one of the following methods:

  • Command ⌘ Shift ⇧ E

  • View > Zoom Editor In

  • Drag the splitter (between the editor window and the file list above it) upwards.

Community
  • 1
  • 1
mmalc
  • 8,201
  • 3
  • 39
  • 39
  • 18
    It took me AGES to find out how to hide the tree as well - Command-Option-Shift-E. Ah, sweet relief. I'm forever indebted to the MacMacDev Glasgow group for letting me know this. – John Gallagher Oct 12 '09 at 09:01
67

Get Colin Wheeler's Complete Xcode Keyboard Shortcut List (available as PDF or PNG). Print it and keep it somewhere visible (I've got it on the wall next to my screen).

edit: Updated versions for Xcode 3.2

edit 2: Updated versions for Xcode 4

Hagelin
  • 16,440
  • 5
  • 29
  • 37
52

Not much of a keyboard shortcut but the TODO comments in the source show up in the method/function dropdown at the top of the editor.

So for example:

// TODO: Some task that needs to be done.

shows up in the drop down list of methods and functions so you can jump to it directly.

Most Java IDEs show a marker for these task tags in the scrollbar, which is nicer, but this also works.

  • 4
    I just tried // MARK: and it has the exact same effect as #pragma mark. You can even use // MARK: with a dash to get the separator. – Rose Perrone Sep 02 '10 at 04:12
  • 1
    I wish you could add markers to the list of things it catches. The code base I work on has a lot of `# XXX`, and it doesn't see those. – asmeurer Dec 28 '10 at 06:23
  • @Gonzalo Larralde What? I don't mean writing // TODO, I mean seeing all the TODO comments in the dropdown bar. #failatfailing – ingh.am Jun 22 '11 at 12:04
  • 5
    In Xcode 3 TODO comments can be placed anywhere in the code and they will appear in the function popup. For some reason in Xcode 4 TODO comments must be outside any function/method body to appear. It's a bug. – SteveCaine Sep 27 '11 at 20:31
  • @SteveCaine months later, is it still a bug, or is it now just reality? – Dan Rosenstark Feb 12 '12 at 23:04
51

⌘-[ and ⌘-] to indent and unindent selected text. Makes cleaning up source code much easier.

Michel
  • 1,456
  • 11
  • 16
43

Hold Option while splitting windows to split vertically rather than horizontally.

42

Double-click on the square brackets or parentheses to obtain bracket and parentheses matching.

Julien Chastang
  • 17,592
  • 12
  • 63
  • 89
36

Control Xcode's text editor from the command line: xed

> xed -x                # open a new untitled document
> xed -xc foo.txt       # create foo.txt and open it
> xed -l 2000 foo.txt   # open foo.txt and go to line 2000

# set Xcode to be your EDITOR for command line tools
# e.g. for subversion commit
> echo 'export EDITOR="xed -wcx"' >> ~/.profile

> man xed               # there's a man page, too
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Nikolai Ruhe
  • 81,520
  • 17
  • 180
  • 200
31

"Ctrl+Left/Right Arrow" to do intra-word text navigation. I use this feature to jump the cursor from the one "camel hump" in a variable to the next.

Matt Dillard
  • 14,677
  • 7
  • 51
  • 61
30

Xcode supports text macros that can be invoked via the Insert Text Macro menu at the end of the Edit menu. They can also be invoked using Code Sense, Xcode's code completion technology.

For example, Typing the key sequence p i m control-period will insert #import "file" into your code, with file as an editable token just like with code completion.

Chris Hanson
  • 54,380
  • 8
  • 73
  • 102
30

Right click on a variable in your function and click edit all in scope. Been using it a lot since I found this out.

ctrl T

Gareth Davis
  • 27,701
  • 12
  • 73
  • 106
robottobor
  • 11,595
  • 11
  • 39
  • 37
28

You can have Xcode run the preprocessor over your Info.plist file:

        <key>CFBundleShortVersionString</key>
    #ifdef DEBUG
        <string>1.0 (debug)</string>
    #else
        <string>1.0</string>
    #endif

See http://developer.apple.com/technotes/tn2007/tn2175.html for details.

Dewayne Christensen
  • 2,084
  • 13
  • 15
  • 16
    Note that if you do this, your Info.plist will always have to be edited as text; you won't be able to edit it in the nice Property List Editor that keeps it using correct keys and value types. – Chris Hanson Oct 01 '08 at 07:46
27

Debugging - how to use GDB

Being new to this still, I find trapping and identifying faults a rather daunting job. The console, despite it being a powerful tool, usually does not yield very intuitive results and knowing what you are looking at in the debugger can be equally difficult to understand. With the help of some of they guys on Stack Overflow and the good article about debugging that can be found at Cocoa With Love it becomes a little more friendly.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Joe
  • 173
  • 4
  • 12
26

Navigate among open files back and forth:
⌥⌘←
⌥⌘→

hasseg
  • 6,787
  • 37
  • 41
Vladimir Grigorov
  • 10,903
  • 8
  • 60
  • 70
25

Technically an Interface Builder tip, but they're a book-matched pair, so I don't think this is off topic...

Shift + Right Click on one of your controls and you get a nice pick list of the object hierarchy. No more click, click, click, frustration!

blissapp
  • 1,330
  • 12
  • 19
22

With Trackpad:

  • Swipe Three Fingers Up - Switch between header and source file, which is easier than Cmd + Opt + Up;
  • Swipe three fingers down - Switch between declaration and definition when selecting a class or method, found these two kind currently;
  • Swipe three fingers left - Go back (Cmd + Opt + Left);
  • Swipe three fingers right - Go forward (Cmd + Opt + Right);

Tested with Xcode 3.2.5.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Míng
  • 2,500
  • 6
  • 32
  • 48
21

The class browser in Xcode! Reached by pressing shift + + c. You can reduce the scope to only show your active project. It gives you a less cluttered view as long as you only want to browse the class hierarchy.

ingh.am
  • 25,981
  • 43
  • 130
  • 177
Chris Schreiner
  • 824
  • 8
  • 15
  • Wow! Did not know this one... this may become my main "working" window. Almost feels like VisualAge (the good parts) :D – rcw3 Jan 19 '10 at 21:48
  • AAARRGGHH As an old ObjectMaster fan, I was happily reading about this until I realised it was removed in XCode4, can't believe what a giant step backwards this IDE is. I bet there's a ton of people inside Apple still using Xcode 3. – Andy Dent Jan 24 '12 at 14:04
19

Using ] to automatically insert [ in the correct location

I come from a .NET background, so I'm used to typing a symbol and then typing one of its method names. So I always forget to include the [ before I start typing the object name. Usually this meant I would need to go to the beginning of the line and add the [ manually. I didn't realize I could just press ] at the current cursor position, and it will be added automatically.

There are ways to use this: either after typing the function's name, or right before typing the function's name.

Method 1: after the function name

myObject testMethod]

... becomes:

[myObject testMethod]

... with the caret positioned after the ].

Method 2: before the function name

myObject]

... becomes:

[myObject ]

... with the caret positioned right before the ].

The advantage of the latter (2) is that code completion will filter on the methods of your object. Whereas with the former (1) if you try to invoke code completion immediately after myObject, it won't be filtered. Another advantage to (2) is it behaves more like other programming languages that use dot notation. You type the name of the object then simply ] instead of . to access a method.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Senseful
  • 86,719
  • 67
  • 308
  • 465
17

Select a block of text and type cmd-/ to comment it out. Do it again to remove the comments characters.

This is especially useful when combined with brace-matching by double-clicking on balanced chars (parens, braces, brackets).

Frank Szczerba
  • 5,000
  • 3
  • 31
  • 31
  • The Xcode commenting/uncommenting was hoplelessly broken last time I checked. It's a shame. – Joe Oct 20 '11 at 13:58
16

Being able to quickly see all the methods that can be overriden from a super class. For example when extending UITableViewController I just type in my implementation:

- ta

and then I hit ESC to see all the methods from my superclass that begin with "ta" such as

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

This also works when adopting protocols.

nicktmro
  • 2,298
  • 2
  • 22
  • 31
14

ctrl + alt + + r to clear the log

Louis Nguyen
  • 304
  • 2
  • 12
Nick Van Brunt
  • 15,244
  • 11
  • 66
  • 92
14

Command ⌘ alt ⌥ shift T : reveal the current edited file in the project tree.

mipadi
  • 398,885
  • 90
  • 523
  • 479
VdesmedT
  • 9,037
  • 3
  • 34
  • 50
  • fantastic tip, thank you. This is so useful when working on someone else's code, like when you are called in to work on a project after it has been in development a while. – Aran Mulholland Oct 07 '10 at 23:28
13

When using Code Sense with many keyboards, use control + , to show the list of available completions, control + . to insert the most likely completion, and control + / & shift + control + / to move between placeholder tokens. The keys are all together on the keyboard right under the home row, which is good for muscle memory.

Louis Nguyen
  • 304
  • 2
  • 12
Chris Hanson
  • 54,380
  • 8
  • 73
  • 102
  • 2
    instead of using control-comma for the list of available completions, you could use esc also. – tmadsen Feb 08 '10 at 07:25
13

Use the Class Browser to show inherited methods

Apple's API reference documentation does not show methods inherited from a superclass. Sometimes, though. it's useful to be able to see the full range of functionality available for a class -- including a custom class of your own. You can use the Class Browser (from the Project menu) to display a flat or hierarchical list of all the classes related to a current project. The upper pane on the right hand side of the browser window shows a list of methods associated with the object selected in the browser. You can use the Configure Options sheet to select "Show Inherited Members" to show inherited methods as well as those defined by the selected class itself. You click the small book symbol to go to the corresponding documentation.

mmalc
  • 8,201
  • 3
  • 39
  • 39
12

Might go without saying, but if you want to use intra-word navigation, make sure you change the key presets in for Spaces (in the Expose & Spaces preference pane), if you use it.

I switched Spaces to use Ctrl-Option Left/Right.

Edit: To set Spaces to Ctrl-Option Left/Right, select the "To switch between spaces:" popup and hold down the Option key. The first item will change from Ctrl Arrow Keys to Ctrl-Option Arrow Keys.

Jablair
  • 5,036
  • 4
  • 28
  • 37
  • How do you set spaces to use Ctrl+Option arrow keys? THe options in SYstem Preferences only allowed either Option, Control, or Cmd – Kevin Chan Oct 04 '08 at 05:55
10

Cmd-/ to automatically insert "//" for comments. Technically the same number of keystrokes, but it feels faster...

Also the default project structure is to put resources and class files in separate places. For larger amounts of code create logical groups and place related code and xib files together. Groups created in XCode are just logical structures and do not change where your files are on disk (though you can set them up to replicate a real directory structure if you wish)

Kendall Helmstetter Gelner
  • 74,769
  • 26
  • 128
  • 150
  • 7
    You can actually select a block of text to toggle comment with CMD-/ – leolobato Aug 06 '09 at 01:43
  • 3
    It feels faster because it is, for //, time is doubled since you can't press the other / with your other hand :) – ustun Oct 14 '09 at 18:35
  • TextMate does this better & faster. Better: In TextMate, it works to uncomment even if there's white space before the comment delimiter whereas, in Xcode, the delimiter cannot have white-space before it. Faster: Xcode has a slight delay for some reason. – ma11hew28 Nov 18 '10 at 17:44
10

Print Complete Xcode Keyboard Shortcut List and put it next to your monitor.

Nikita Zhuk
  • 367
  • 4
  • 9
10

pragma mark

Example:

#pragma mark === Initialization ===

Writing this line above all initialization methods will generate a nice heading in the dropdown menu above the editor.

Open Quickly

Shift + cmd + D Start typing a file name you'd like to open. Very cool if you look for framework headers. They have nice comments too, sometimes additional info to the docs.

ESC

When your text-cursor is on a uncomplete method name for example, press ESC. It will shop up everything that might fit in there, and you can quickly complete very large method names. It's also good if you can't remember exactly the name of a method. Just press ESC.

I think these are the best ones I know until now.

(Migrated from deleted question by Stack Overflow user Thanks.)

Community
  • 1
  • 1
Jeff Atwood
  • 63,320
  • 48
  • 150
  • 153
9

Use ^T to swap the previous two letters

This works in all Cocoa apps, but I like it especially when coding. Use ^T (Control-T) to swap the two letters adjacent to the caret, or when the caret is at the end, the two letters before the caret. For example:

fi^T

... becomes:

if

... which is a common typo I make.

Johan Kool
  • 15,637
  • 8
  • 64
  • 81
  • A lot of the basic emacs key bindings work in Xcode, and in all Cocoa text fields throughout the OS. Give 'em a try. – macserv Feb 03 '12 at 23:31
9

Recompile-free debug logging

cdespinosa's answer to Stack Overflow question How do I debug with NSLog(@“Inside of the iPhone Simulator”)? gives a method for a debugging-via-logging technique that requires no recompilation of source. An amazing trick that keeps code free of debugging cruft, has a quick turnaround, and would have saved me countless headaches had I known about it earlier.

TODO comments

Prefixing a comment with TODO: will cause it to show up in the function "shortcut" dropdown menu, a la:

int* p(0); // TODO: initialize me!
Community
  • 1
  • 1
fbrereto
  • 35,429
  • 19
  • 126
  • 178
8

⌘` to properly format (reindent) your code

EDIT: Apparently re-indent feature (Edit > Format > Reindent) has no default shortcut. I guess I assigned one (in Preferences > Key bindings) a long time ago and don't even remember about that. Sorry for misleading you.

Thomas
  • 547
  • 5
  • 12
8

Build success/failure noise; from term:

defaults write com.apple.Xcode PBXBuildSuccessSound ~/Library/Sounds/metal\ stamp.wav
defaults write com.apple.Xcode PBXBuildFailureSound ~/Library/Sounds/Elephant
geowar
  • 4,397
  • 1
  • 28
  • 24
  • Some people have commented (privately) that the above didn't work for them; when we investigated it turns out they didn't have those sound files in their <~/Library/Sounds/> directory… so… note to anyone that tries this: make sure these defaults point to (sound) files that actually exist… ;-) – geowar Sep 04 '10 at 22:14
8

Right click on any word and select 'Find Selected Text in API Reference' to search the API for that word. This is very helpful if you need to look up the available properties and/or methods for a class. Instead of heading to Apple.com or Google you will get a popup window of what you were looking for (or what was found).

kdbdallas
  • 4,513
  • 10
  • 38
  • 53
8

For me it’s always been: Command ⌘ + 0:

After you debug or run or anything, if you quit the iPhone Simulator or the debugging app, you’re left with the debugger window.

When you’re using “Single-Window Layout”, going back to the editor must be done with a click in the toolbar which is annoying (plus you later need to “remove the detail pane”).

The above shortcut does it and leaves you ready to code.

Martin Marconcini
  • 26,875
  • 19
  • 106
  • 144
8

In PyObjC, you can do the equivalent of #pragma mark for the symbols dropdown:

#MARK: Foo

and

#MARK: -

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Dan
  • 2,766
  • 3
  • 27
  • 28
  • This also works in Objective-C with //MARK:. Faster to write than #pragma mark. – omz Jan 16 '11 at 09:42
7

A. It will build and analyze, meaning that Xcode will warn you about possible leaks.

tmadsen
  • 941
  • 7
  • 14
7

Cmd + Ctrl + up / down collapses all of your functions or uncollapses them.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Johnny Mast
  • 703
  • 1
  • 9
  • 17
7
  1. Hold down option while selecting text to select non-contiguous sections of text.
  2. Hold down option while clicking on the symbol name drop down to sort by name rather than the order they appear in the file.
Mike Akers
  • 12,039
  • 14
  • 58
  • 71
  • 1
    Technically, it's square text selection (not really the same as non-contiguous selection). This also works in many other Cocoa programs too, like Terminal. – asmeurer Dec 28 '10 at 06:31
7

One more .... Hex Color Picker... it add's hex tab to your interface builder's color panel ... so now you can use hex color directly from Interface Builder..

alt text

k-thorat
  • 4,873
  • 1
  • 27
  • 36
  • 5
    +1 although the [Developer Color Picker](http://www.panic.com/~wade/picker/) is nicer because it also includes options for copying it the color with various declarations (CSS, `NSColor`, `UIColor`, etc) – Dave DeLong Nov 11 '10 at 22:17
7

Being able to split the current editor window horizontally, which is great for wide screen monitors to be able to view the source and header file side by side. There are two different methods for doing depending on what version of Xcode you are using.

In Xcode 3.0 it is under Preferences, Key Bindings, Text Key Bindings at the bottom of that list.

In Xcode 2.5 it is under Preferences, Key Bindings, Menu Key Bindings, View menu.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mark
  • 6,108
  • 3
  • 34
  • 49
  • 1
    ⌘' closes the current split (under "Close Split" in the bindings list). – Dan Jan 28 '09 at 22:26
  • 1
    There is also an icon to do this at the top of the scroll bar, it looks like a split window (and after splitting, another unsplit window icon appears to remove the split). – Frank Szczerba Apr 10 '09 at 18:28
  • I believe that that button only splits horizontally so that the files are on top of each other. I prefer splitting vertically so that the header file is to the right of the *.m file. – Mark Apr 11 '09 at 14:33
  • 1
    As noted elsewhere in this thread, if you click while holding Option, it will split the other way. – ustun Oct 14 '09 at 18:38
7

Highlight Blocks of Code (Focus Follows Selection)

Activate "Focus Follow Selection" from View -> Code Folding -> Focus Follows Selection or ControlOptionf.

This also works for Python code, but leading whitespace in a line will throw it off. To fix it, install Google's Xcode Plugin and activate "Correct Whitespace on Save" in the preference thing that it installs. This will clear trailing whitespace every time you save a file, so if the highlighting get's screwed up, you can just save the file and it will work again. (And see, this is actually two hints in one, because this feature from the plugin is useful to have on its own).

Here is an example with some random Python code I just wrote. I am using the Midnight Xcode syntax coloring theme.

Some random Python code.

This is really helpful for highly nested parts of the code, to keep track of what is where. Also, notice how on the left, just to the right of the line numbers, those parts are colored too. That is the code folding bar. If you run your mouse down the side, it highlights the part under the mouse. And any of those colored bars can be folded, in other words, the parts of the code that are highlighted are exactly those parts that can be folded.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
asmeurer
  • 86,894
  • 26
  • 169
  • 240
  • 1
    re: "pictures of keys". A limited set of HTML tags are supported by Markdown. See http://meta.stackexchange.com/questions/1777/what-html-tags-are-allowed. I think the `kbd` tag was used. – David J. Liszewski Dec 28 '10 at 14:48
7

I just discovered how to change the indentation behavior used in the text macros:

For example, if you are like me and don't like this:

if (cond) {
  code;
}

but prefer this instead:

if (cond)
{
  code;
}

then you can change this globally (for all languages) by setting the following defaults in the terminal:

defaults write com.apple.Xcode XCCodeSenseFormattingOptions -dict-add BlockSeparator "\n"

This has been bugging me for years, I hope it is of some interest for someone else as well.

The documentation for this feature can be found in the Xcode User Default Reference

monsterkodi
  • 21
  • 1
  • 2
7

enter image description here

  1. To Open the debugging window on Debugger starts Change the Debugging preferences shown in the image..

  2. To clear the console log everytime app runs, check the Auto clear Debug Console.

k-thorat
  • 4,873
  • 1
  • 27
  • 36
6

Use AppKiDo to browse the documentation.

Use Accessorizer for a bunch of mundane, repetitive tasks in Xcode.

James Moore
  • 8,636
  • 5
  • 71
  • 90
6

When you use code completion on a method and it has multiple arguments, using CTRL + / to move to the next argument you need to fill in.

crackity_jones
  • 1,077
  • 2
  • 13
  • 16
6

A different way to set the your company name in a project template is to:

  • Add a contact for yourself in Address Book
  • Edit Company field in your contact to your Company name
  • Now select your contact then go to menu and select Card -> Make This My Card
  • Your contact card should now be bold in address book to confirm this.

This should now add your company name to all your project templates as well as providing other applications with more autofill information!

Daniel Granger
  • 1,334
  • 1
  • 16
  • 36
6

To display the current autocompletion options in a popup menu by default (without having to press ESC first), type

defaults write com.apple.Xcode XCCodeSenseAutoSuggestionStyle List

in the Terminal and restart Xcode.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ole Begemann
  • 135,006
  • 31
  • 278
  • 256
  • Reminder: use this command only when Xcode is already closed, or the way `NSUserDefaults` work may overwrite the change (rare but may happen). – millenomi Dec 15 '10 at 10:55
  • Btw, how to set default behavior for that feature? Property access notation like 'self.frame' - is not support autocomplete with this feature. Also you can use Cmd+Space to see suggestions window. – Valerii Pavlov Nov 23 '11 at 13:43
6

The User Scripts menu has a lot of goodies in it, and it's relatively easy to add your own. For example, I added a shortcut and bound it to cmd-opt-- to insert a comment divider and a #pragma mark in my code to quickly break up a file.

  #!/bin/sh
  echo -n "//================....================
  #pragma mark "

When I hit cmd-opt--, these lines are inserted into my code and the cursor is pre-positioned to edit the pragma mark component, which shows up in the symbol popup.

Ben Gottlieb
  • 85,404
  • 22
  • 176
  • 172
6

Xcode code formatting... is one of the thing you need when you want to make your code readable and look good.

You can do the code formatting by yourself or save some time using scripts.

One good way is.. use Uncrustify. It is explained in Code Formatting in Xcode.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
k-thorat
  • 4,873
  • 1
  • 27
  • 36
  • +1 for Uncrustify, even though it's not strictly an Xcode tip. Xcode is useless at keeping track of whitespace and indentation. – Jakob Borg Sep 16 '10 at 19:47
6

Check out a nice screencast about 'becoming productive in Xcode': becoming-productive-in-xcode

6

If you have a multi-touch capable Mac - use MultiClutch to map some of the keystrokes described by mouse gestures.

I use three finger forward and back to go forward and back in file history (cmd-alt-.), and pinch to switch between .h and .m.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
TimM
  • 336
  • 4
  • 11
  • Nowadays, you should use [BetterTouchTool](http://blog.boastr.net/), which works in Snow Leopard and is in active development. – asmeurer Dec 28 '10 at 06:33
5

To link a new framework

(In the Groups and Files pane, open the Targets disclosure triangle to display the targets associated with your project.)

  1. In the Groups and Files pane, double-click your current project target to display the Target Info panel.
  2. In the Info panel, select the General tab. The lower pane displays the currently-linked frameworks.
  3. Add a new framework by pressing the + button at the bottom left of the panel and selecting from the list presented in the sheet that appears. (Importantly, the list in the sheet shows only the frameworks relevant to the target...)

(This wasn't available two years ago, but it's nevertheless worth pointing out as a significant time-saver over finding the framework in the filesystem and dragging it into the project...)

mmalc
  • 8,201
  • 3
  • 39
  • 39
5

Ctrl-left/Ctrl-right to navigate words within a variable or method name. Can't live without this one.

John Gallagher
  • 6,208
  • 6
  • 40
  • 75
5

Key bindings to Xcode actions

I also adore the "re-indent". True there is no default shortcut, but you can add one from the Text Key Bindings tab of the Key Bindings preference pane.

Which is a time-saver all on its own. Just lookup your favorite actions and add/edit keyboard shortcuts!

One set of defaults I do find handy are the CMD+" and CMD+' to add/remove vertical splits. Hold down option for these and now you have the same for horizontal. But if these gestures don't work for you, you can always change them.

Paxic
  • 1,760
  • 16
  • 28
Old McStopher
  • 6,295
  • 10
  • 60
  • 89
5

When typing a method press ESC to see the code completion options (no doubt this has been mentioned before). I already knew about this, but TODAY I discovered that if you press the button in the lower-right-hand corner of the code completion window (it'll be either an 'A' or Pi) you can toggle between alphabetical sorting and what appears to be sorting by class hierarchy.

All of a sudden this window is useful!

kubi
  • 48,104
  • 19
  • 94
  • 118
5

As for "Open Quickly" feature - it's great, but I've always missed TextMate's cmd-shift-t for browsing the projects and files (symbols, methods, etc).

That's why I've released an Xcode plugin that provides just that. It's called Code Pilot and you might want to take a look at it: http://macoscope.net/en/mac/codepilot/

kodz
  • 393
  • 3
  • 8
  • Code pilot looks promising. At first use I've noticed that you cannot paste into the search field. Is that right? – Nikolai Ruhe May 17 '10 at 17:58
  • 1
    Copying, pasting, along with automatic copying what you have selected in the editor window into Code Pilot are among the upcoming features - should be available shortly. – kodz May 22 '10 at 08:59
  • Open quickly ... I was looking for this option for long time. But did not know 'open quickly' means that. What a dumb I am! I never tried what it do! Thanks a lot. – karim Feb 23 '11 at 09:10
5

In shell build phases you can write to stderr using the following format:

<filename>:<linenumber>: error | warn | note : <message>\n

It's the same format gcc uses to show errors. The filename:linenumber part can be omitted. Depending on the mode (error, warn, note), Xcode will show your message with a red or yellow badge.

If you include an absolute file path and a line number (if the error occurred in a file), double clicking the error in the build log lets Xcode open the file and jumps to the line, even if it is not part of the project. Very handy.

Nikolai Ruhe
  • 81,520
  • 17
  • 180
  • 200
5

Control+R to execute selected text as a shell script which returns with the pasted output following the selection!

humasect
  • 552
  • 5
  • 9
5

Select a block of text and use

Command + '/' 

To comment out the block of text. Selected the commented block and use the same shortcut to uncomment it.

gnuchu
  • 1,496
  • 13
  • 21
  • cool. now I wonder how to do that in Ruby in Netbeans, where we cannot use `/*`... – Dan Rosenstark Aug 11 '10 at 13:24
  • Why doesn't that work for me ? I only know that shortcut from eclipse and I think tried it from the beginning as I came to XCode 3.x. I can only test it in XCode 4 now and it doesn't work there either. – Allisone Aug 18 '10 at 11:21
  • Update... it works fine in XCode 3.2, I was forced to reinstall 3.2 (got broken recently cause I played with forbidden files) and now I can use this shortcut. Still doesn't work in XCode 4 though (which I reinstalled too, to have everything fresh and clean) – Allisone Aug 19 '10 at 11:32
4

Move back or forward a full word with alt-. Move back or forward a file in your history with cmd-alt-. Switch between interface and implementation with cmd-alt-.

Jump to the next error in the list of build errors with cmd-=. Display the multiple Find panel with cmd-shift-f. Toggle full editor visibility with cmd-shift-e.

Jump to the Project tab with cmd-0, to the build tab with cmd-shift-b and to the debug tab with cmd-shift-y (same as the key commands for the action, with shift added).

Jason Harris
  • 2,317
  • 17
  • 10
4

Sort contents of Groups in Xcode's Groups and Files pane by selecting the Group, then Edit > Sort By > Name.

You would expect to find this in the contextual menu for the group, but it isn't there.

Credit: Sorting of files in Xcode.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Matt Andersen
  • 4,816
  • 3
  • 24
  • 19
  • This is a good one. One of my favs. I also setup a key binding so I don't have to go to the menu. I like cmd+shift+z – gngrwzrd Apr 26 '10 at 07:46
4

I have created my own file templates for NSObject, UIView and UIViewController so when I create new classes, the files are all set up with private sections and logging of class' address in init and dealloc.

Example (NSObject derived class named 'test' will start like this):

//=====================================================
// Private Interface
//=====================================================

@interface test (private)
@end

//=====================================================
// Public Implementation
//=====================================================

@implementation test

- (void)dealloc {
    NSLog(@">>> Dealloc: test [0x%X]", self);
    [super dealloc];
    NSLog(@"<<< Dealloc: test");
}

- (id) init
{
    self = [super init];
    if(self) {
        NSLog(@">>> Alloc: test [0x%X]", self);
    }
    return self;
}

@end

//=====================================================
// Private Implementation
//=====================================================

@implementation test (private)
@end

Plenty of resources are available for this, for example Cocoa dev: Design your own Xcode project templates.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
LK.
  • 4,499
  • 8
  • 38
  • 48
  • As of ObjC2, you can use an extension instead of a category to implement private methods by simply omitting the category name (i.e just have "@interface test ()" ). This works like a category would except it expects the methods to be implemented in the main implementation block. I prefer it because it lets me put the private methods right with related public ones. – Boaz Stuller Apr 26 '10 at 14:58
  • Oh - thanks. I actually use this convention of separating the two in C++ too so I guess it is just individual taste – LK. Apr 26 '10 at 15:47
4

There are many adjustments you can make to how Xcode treats the formatting of your code, but only if you change the settings via command line. I threw together a little program that lets you adjust them to your liking. Enjoy :)

Xcode Formatting Options

Tyler
  • 1,603
  • 13
  • 21
4

Some tips to be found in Xcode Tools Tips.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Joe
  • 173
  • 4
  • 12
4

Cmd + ~ (tilde - looks weird on the button...)

To switch between any open Xcode window - also when multiple projects are open.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
LK.
  • 4,499
  • 8
  • 38
  • 48
3

If the hilighting gets messed up, if your ivars aren't hilighted or anything else, just do ⌘-A ⌘-X ⌘-V, which will select all, cut, and paste and all the hilighting will be corrected. So just hold down ⌘ and press A then X then V.

mk12
  • 25,873
  • 32
  • 98
  • 137
3
  • To "set next statement", just drag the red instruction pointer to the next line to execute. (source)
Chris R. Donnelly
  • 3,086
  • 3
  • 28
  • 28
3

Alt-Left & Right to go to the end/start of the line. This along with the CTRL-Left & Right to move to the next capital letter, or word break. these two save me so much time

Aran Mulholland
  • 23,555
  • 29
  • 141
  • 228
3

I don't really like the code-formatting/reindent feature that is built into xcode, so I found using uncrustify as a code formatter very useful. It can be used as a User Script: http://hackertoys.com/2008/09/18/adding-a-code-beautifier-script-to-xcode/

cahlbin
  • 1,039
  • 10
  • 17
3

Use xcodebuild command line to do a clean build on the shared build machine:

cd project_directory
xcodebuild -configuration Release -alltargets clean
xcodebuild -configuration Release -alltargets
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
billo
  • 51
  • 3
3

My favorites have to be these general editor shortcuts:

  • + 0 returns you back to your editor from debug mode.
  • + Shift + R takes you from debug mode to editor view (project mode)
  • + Shift + E "maximizes" the editor (This is very useful when you have build results, etc. displayed above your editor and you just want to make your source editor taller)
  • Ctrl + 2 displays an outline of your current code
  • + Return runs the application
  • + Shift + Return ends the application
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Debajit
  • 46,327
  • 33
  • 91
  • 100
3

Pressing ⌥⇧⌘D activates "Open this Quickly", which navigates you to the first result from "Open Quickly" using the selected text. If the selected text is in the format <filename:lineNumber>, (with or without <>) "Open this Quickly" takes you to the file plus line number.

You can combine this with the following tip:

You can write logs that contain the filename and line number of the log entry using this macro: (Make sure to define -DDEBUG=1 on your C Flags used in your target's debug configuration)

#ifdef DEBUG
#define DLog(fmt, ...) NSLog((@"%s <%@:%d> " fmt), __PRETTY_FUNCTION__, [[NSString stringWithFormat:@"%s", __FILE__ ] lastPathComponent] ,__LINE__, ##__VA_ARGS__)
#else
#define DLog(format, ...)
#endif

In your DLog() output, double-clicking on the "<" character to select the <filename:lineNumber> and pressing ⌥⇧⌘D will open the line where the log is in the source code.

Juan Arzola
  • 453
  • 4
  • 6
2

I find that using the shortcuts for building/cleaning and running your project really saved me some time:

  • Cmd-R: Build & Run
  • Cmd-Y: Build & Debug
  • Cmd-Shift-Enter: Stop running project
  • Cmd-Shift-K: Clean build
NSSec
  • 4,431
  • 1
  • 27
  • 29
2

The entire shortcut list can be found here: http://iphonehuston.blogspot.com/2009/08/shortcuts-for-xcode.html

amok
  • 1,736
  • 4
  • 20
  • 41
2

The fact that I can use Emacs as my editor and Xcode as my builder/debugger... Best of both worlds, in my humble opinion.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Brian Postow
  • 11,709
  • 17
  • 81
  • 125
2

I have no idea if everybody knows this already, but I was delighted when I learned I could use "code folding" and hide nested functions that I didn't want to look at by clicking on the gray area nearest to the code that you want to fold.

Hard to explain . . .

Kevin Yap
  • 670
  • 10
  • 22
2

Rename a file shared by multiple projects:

  1. Open all the projects.
  2. Rename the file in one project.
  3. Xcode automatically adjusts all the open projects to reflect the file's new name.
Steven Fisher
  • 44,462
  • 20
  • 138
  • 192
2

Snapshots, File>Make Snapshot, provides a quick way to save a revision of your project if you aren't using a proper version control system. Great way to experiment with a large, potentially damaging change.

Chris Wagner
  • 20,773
  • 8
  • 74
  • 95
2

Show chooser for open symbol

⌘ + ⌥ + ⇧ + click over a symbol

Shows

enter image description here

You can choose open the symbol in:

  • the current tab
  • in an existing tab
  • in a new one (with the + in the upper right corner)
  • in a vertical split (with the + in the right) or
  • in a new window (with the + in the left).
Bruno Berisso
  • 1,091
  • 11
  • 33
1

Code Completion

stackr
  • 2,742
  • 27
  • 44
1
  1. Cmd+Option+O to open a file in a separate window.
  2. Can configure Tab to always indent. I frequently use it to indent an entire file.
  3. Ctrl+Arrow keys to move between camel case words. If you have OneTwo, you can move from One to Two with Ctrl+Right arrow.
  4. You can use emacs bindings, there's even kill ring! I use the Ctrl+w and Cmd+C together when I need to copy two different pieces of text.
  5. In the documentation browser, you can restrict your searches to a particular library, e.g., just iOS 4.2 library. This helps me focus on API available only on a particular iOS/Mac version of the SDK.
  6. Cmd+Shift+A to build and analyze.
Plumenator
  • 1,682
  • 3
  • 20
  • 49
-3

I came into Xcode right from Windows world (as MANY others), and one of the first quirks which I was faced to, was trying to "indent a selected block of text" with the TAB key.

Typically, when using a Windows editor, you select a block of text, and whenever you press TAB (or shift TAB) keys, the selected text jumps right/left. Then, once you decide the new position of the text, you stop pressing TAB.

OK, in Xcode, this is completely different, because when you press TAB, the whole block of text disappears, leaving you with a silly face, and some anger inside...

But then, just by chance or intuition or something, one day I discovered some kind of workaround to achieve the same effect you might get under a proper windows editor. The steps should be these:

  1. Select the text block as you might do under Windows.
  2. Instead of pressing TAB, leave your instincts away, and "copy the text block" (typically CTRL+C (yuck)).
  3. Then, without deselecting the text, (pressing SHIFT if needed), extend the beginning of the selection and place it on the position you would like your new text to appear.
  4. Paste the beforementioned text (typically CTRL+V (yuck again)).
  5. Result: The previous text block gets substituted by "the new" one (of course, itself), but the "auto indent" capabilities of Xcode (or someone else, who cares), will auto place the text starting onto the new position we chose in step 3.
  6. A big smile appears on your face.

It's kind of tricky, but when you get used to it, you find yourself using it a lot.

Enjoy!!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Isaac
  • 1,794
  • 4
  • 21
  • 41
  • 9
    To tab lines/code blocks left and right in Xcode, you just use Command+] (for right, Command+[ for left). If you're just tabbing a single line, then you don't even need to select, just have the cursor located somewhere within the line. – Brock Batsell Feb 11 '11 at 08:56
  • That would be really nice, if it wasn't because in the vast majority of the world, the '[', ']', '/'... symbols/keys are not single keystroked like in the US-centric programming world. So what happens? MANY useful tricks (like yours) get obscured and hidden among rare key-combinations... But in this case, your key combination is a lucky one!! In my es_ES keyobard it becomes Command+ALT+ (^`[) and it's quite practical! BIG THANKYOU! – Isaac Feb 11 '11 at 09:13
  • 4
    I have the key combination `Command-Control-backslash` bound to "Re-Indent" to do exactly what you describe. (To customize keybindings: Xcode > Preferences > Key Bindings > Edit > Format > Re-Indent) – cobbal Feb 11 '11 at 15:13