When I select multiple lines of code and want to indent them as usual with TAB key, it just deletes them all. I come from Eclipse where I always did it that way. How's that done in Xcode? I hope not line by line ;)
20 Answers
Here are the shortcuts, to format the code in XCode
Format entire code (entire class/controller)
Select the entire code and press control+I on mac to format your code.
Format particular block of code
Select the code and press:
- ⌘+] for right move (indent)
- ⌘+[ for left move (un-indent)
Note: as per @JavierGiovannini sugesstion you can do using Editor Menu option
- Select your code and navigate to Editor > Structure > Re-Indent
Select "Tab key: Indents always" in Preferences->Text Editing->Indentation Then you can indent a single line or a selection of lines by pressing TAB or SHIFT+TAB Sadly this removes altogether the possibility to insert tabs where you want, and conflict badly with the tab key being used to switch between "autocompletion fields".
I guess we need more tab keys in the keyboard, one is not enough...
If you want to remap the standard Xcode's ⌘+[ to TAB, you can do the following:
Install a program called "Karabiner".
Go to Preferences ~> "Misc and Uninstall"
In "Custom Setting" section click on the "Open private.xml" button
Open the file and replace its content with the following code:
<?xml version="1.0"?> <root> <item> <name>Tab instead of Command+[</name> <identifier>private.swap_tab_and_cmnd+[</identifier> <autogen> __KeyToKey__ KeyCode::TAB, ModifierFlag::NONE, KeyCode::BRACKET_RIGHT, ModifierFlag::COMMAND_L | ModifierFlag::NONE </autogen> </item> </root>
Go to Preferences ~> "Change Key" ~> click on "Reload XML" button
Put a tick in the checkbox which is called "Tab instead of Command+["
Enjoy
PS: Please note that this setting works globally on your machine, not just in Xcode. However, I am sure that google might help you to find a solution how to customize it even further, applying the changes only to Xcode.
Basically ⌘ [ for left multiple indent and ⌘ ] right multiple indent.
For TR
keyboard you can left multiple indent with ⌘ ⎇ 8 and right multiple indent with ⌘ ⎇ 9.Because both 8 and 9 are ALT
characters of the these nums.Or if you have a keyboard which has [ or ] characters are belong to ALT
(⎇) property so you can use ⌘ ⎇ KEYBOARD CHARACTER
In Xcode 4.2 auto-indenting is pretty good. You can now indent a selection of code by pressing the Tab key. I find that Xcode generally formats code really well automatically, and you rarely have to move things around yourself. I find it faster to select a piece of code, right-click and choose Structure -> Re-indent if some code looks messy.