80

Some projects I work in uses tab key settings that equate to 3 or 4 spaces and another wants actual tabs. Another mixes the two depending on directory.

Is there some way to set these settings per project, or even better, per file? If not, does someone have a clever way of dealing with this? (besides "just remember which setting you should use and change it before you start editing")

mokagio
  • 16,391
  • 3
  • 51
  • 58
Michael Chinen
  • 17,737
  • 5
  • 33
  • 45

6 Answers6

80

This seems to have changed with Xcode 4 ... if you click on a file, group or project, amongst the items in the Utilities bar (at the right-hand side, by default) is 'Text Settings'.

James Turner
  • 2,425
  • 2
  • 19
  • 24
  • I was wondering why my project is ignoring Settings > Text Editing > Indentation... Restarted my mac. Then find this. I was hilarious. Thanks :) – kelin Oct 11 '22 at 20:24
63

You can set indentation per file, group, project, or for all new projects, and for all but per file indentation, new source code files will inherit the indentation settings of the closest parent.

To set indentation per file, select the file in the Project Navigator, and set indentation in the File Inspector ▶ Text Settings.

Xcode indentation per file

To set indentation per group, select the group in the Project Navigator, and set indentation in the File Inspector ▶ Text Settings.

enter image description here

To set indentation per project, select the project in the Project Navigator, and set indentation in the File Inspector ▶ Text Settings.

enter image description here

To set default indentation for new projects, select Xcode ▶ Preferences... ▶ Text Editing ▶ Indentation:

enter image description here

Scott Gardner
  • 8,603
  • 1
  • 44
  • 36
  • 1
    Is there per-filetype indentation setting support in Xcode 9+ ? – studyro Dec 04 '17 at 04:09
  • 2
    Just a note on this - after changing the indentation it doesn't seem to auto apply, you have to `command+a` to select all, followed by `control+i` to force a reformat. (The formatter isn't great in Xcode so be prepared for some crazy indentation rules!) – Neil Palethorpe Mar 20 '19 at 10:52
  • This was the answer to my indentation issue in Xcode 10.1 – Walt Sellers Jul 03 '19 at 16:11
30

The accepted answer is no longer correct.. as of Xcode 5.1.. which forces you now to Edit "per file" indentation settings via..

enter image description here

enter image description here

Alex Gray
  • 16,007
  • 9
  • 96
  • 118
  • 9
    You can select the **project** in the navigator and change the default text settings in the inspector area for any file not otherwise specified. – Steven Fisher Jan 07 '16 at 23:34
  • 1
    In Xcode 10, you'll perform this similarly to Alex Gray's earlier mentioned approach. It is still done under File Inspector. Hope this helps! [File Inspector](https://i.stack.imgur.com/TQUEj.png) – Chioke Aarhus Jun 10 '19 at 01:04
12

Update: This answer only applies to Xcode3. For newer versions, see James Turner's answer.

Yes, go to View > Text > Tab Settings...

There you specify the (file-specific) indentation settings which will be saved in the project.

Philipp Schlösser
  • 5,179
  • 2
  • 38
  • 52
Steven Kramer
  • 8,473
  • 2
  • 37
  • 43
  • If you right click a file or folder in the `Groups & Files` area on the left, then choose `Get Info`, you can also specify tab settings there in the `General` tab. The advantage of doing that on a folder is those settings apply to all files within those folders. Individual files that have ever had a particular setting changed will not change when the same setting is changed in the parent folder. I see no way to make child files track their parent folder setting again short of editing the .pbxproj file to deleting bits like `usesTabs = 0;` within the child file lines. – Winter Dragoness Dec 12 '14 at 18:44
4

Actually Alex Gray and James Turner are the most correct - XCode 5.1 allows you to modify the tab/indent from the File Inspector as you mention, but simply highlight the entire project and it will apply to everything within it (i.e. all files).

BVP
  • 49
  • 1
1

As of 8.3 you can still select project in the navigator and then change the tab/space indent option in the inspector. Worth mentioning though is that it will only change files in folders that have been added with "Create groups" selected instead of "Create folder references" which is the default.

cajjed
  • 113
  • 9