38

I used to use tabs for indentation and spaces for alignment. Like so (arrows show tabs and dots show spaces).

enter image description here

In QtCreator you can set such coding style in standard preferences. I can't find the way to achieve the same goal in Xcode. Could you please tell me if it is possible? May be there is a plugin for that?

UPDATE: Here is how it can be achieved in QtCreator: enter image description here

P.S. Please, don't try to persuade me that using spaces only/tabs only is better, otherwise this question will turn into another holywar :)

Once more about what I'm trying to achieve: Indent with tabs, align with spaces. Vim Tips Wiki.

UPDATE 2: I've just submitted an Apple Radar bug-report (enhancement) rdar://22285639. Here it is on the open radar.

UPDATE 3: I received an answer from Apple. My bug is a duplicate of rdar://8165023.

4
  • I am trying to achieve the same thing. Did you by chance find a solution? Commented Jan 14, 2015 at 11:09
  • @user1264176, unfortunately, no. Xcode 6 is still not capable of such formatting. I had to switch to spaces while working in Xcode. One option is to use AppCode by JetBrains, but it's not free and it still requires Xcode for some actions. So I'm still hoping that Apple will implement it one day, because tabs, the way they are implemented now, are unusable. Commented Jan 14, 2015 at 13:29
  • Thanks for prompt response. I had to switch to spaces too. It is fine if you work with tabs in Xcode but all the other editors or browsers will mess up formatting. Commented Jan 14, 2015 at 13:38
  • @user1264176, unfortunately, Xcode will also mess it up, if you just change the tab width :) Or someone else with a different tab width (for instance, many people prefer 2 spaces instead of 4) will open your project. Commented Jan 14, 2015 at 13:52

3 Answers 3

75
+50

In Xcode > Preferences (,):

> Text Editing > Indentation

If I understand your question correctly, this should do it for you.

2
  • 5
    Thanks! But the problem is that this way it uses spaces everywhere. I want it to use tabs for indentation and spaces for alignment. I like tabs, because they are more flexible. But you can't use them for indentation, because if you changed tab size, for instance, from 4 to 2, your indentation would be ruined. For example, arg2 and arg3 wouldn't be on the same column with arg1. And it seems to me that there is no way to do that in XCode. I will post a screenshot from QtCreator now to illustrate what it looks like there. Commented Apr 28, 2013 at 15:39
  • 5
    Well, your answer is obviously the best :) Sorry, but I can't accept it since it doesn't answer my question completely (what if someone else will show up). But the bounty and an upvote are yours :) Thank you for your attention! Commented May 4, 2013 at 8:34
1

If you want to remap the standard Xcode's +[ to TAB, you can do the following:

  1. Install a program called "Karabiner".

  2. Go to Preferences ~> "Misc and Uninstall"

  3. In "Custom Setting" section click on the "Open private.xml" button

  4. 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>
    
  5. Go to Preferences ~> "Change Key" ~> click on "Reload XML" button

  6. Put a tick in the checkbox which is called "Tab instead of Command+["

  7. Enjoy

enter image description here

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.

2
  • Not what I was looking for,but thanks) Are you related to Karabiner by any chance? You copy-pasted this text in several answers) Commented Dec 10, 2015 at 21:14
  • No, I am not related to Karabiner at all. Have you tried looking at "clang-format" or "uncrustify"? Maybe setting those properly might help? (see example here -- blog.manbolo.com/2015/05/14/code-beautifier-in-xcode)
    – OlDor
    Commented Dec 10, 2015 at 22:35
-3

In XCode
Xcode > Preferences or use ⌘ , to open Preferences
now click on the Text Edit tab and then there is sub tab bar click on Indentation and you can change setting of the Indentation as you need

here is the last view for the preferences

4
  • Thank you, but 1) Your answer completely duplicates Undo's answer; 2) It doesn't answer my question – please, read the discussion under the Undo's answer. Commented Jul 30, 2019 at 8:33
  • well, I think Xcode do not have this, if you see in the appDelegate.swift where long method name with multiple parameters can be found then you will see that apple itself uses same pattern not one you are looking for. For me Xcode do not support it, if you find any solution then share it I will love to see it
    – Sultan Ali
    Commented Jul 31, 2019 at 9:06
  • 3
    Yep, hence my question :) Let's hope Apple implements it one day.Although it is probably too late by now. I can't believe I asked this question over 6 years ago. Time flies. Anyway, thank you! Commented Jul 31, 2019 at 10:46
  • 2
    @SultanAli, please, delete your answer, because it adds nothing to the discussion (full duplicate except for super-tiny and not-so-relevant details) and wastes everybody's time (to read and figure there is no new information) Commented Aug 29, 2019 at 13:59

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