15

I have unchecked both "Show arguments in pop-up list" and "Insert argument placeholders for completions" in Xcode Code Sense preferences, but when I type "else" (for example) in the editor, Xcode still dumps in a pre-formatted "else" block.

Is there a way to disable this feature entirely, or (better yet) to modify the block that Xcode inserts? The default Xcode "else" block doesn't match my coding style, so the placeholder actually hampers my productivity instead of helping.

UPDATE: I just found this question Which describes how to change the default indentation and whitespace used for code completion, so that answers the second half of my question.

UPDATE #2: Setting "Automatically Suggest" to "never", as suggested by outis effectively disables code completion entirely. I suppose what I'm looking for is a way to disable specific code completions, (like the "else" block) while keeping all of the usual completions for variable and method names.

Community
  • 1
  • 1
e.James
  • 116,942
  • 41
  • 177
  • 214
  • Which version of XCode are you using? – outis Feb 07 '10 at 22:57
  • Is XCode inserting the block or merely suggesting it? – outis Feb 07 '10 at 23:04
  • 1
    I'll have to say "suggesting", since it shows up grey and will disappear if I use the arrow keys. The trouble is that it will actually be inserted if I press enter, which is what I would normally do after typing "else". – e.James Feb 07 '10 at 23:07

3 Answers3

9

You can override any of the existing code completions, copy any of the .xtcmacro files from:

/Applications/Xcode.app/Contents/PlugIns/TextMacros.xctxtmacro

(you'll have to right-click on Xcode.app and say "Show Package Contents" to proceed further down the directory chain unless you are using Terminal)

into a local directory:

~/Library/Application Support/Developer/Shared/Xcode/Specifications

(You'll probably have to make the Specifications directory). Then simply go through all of the definitions in there, to eliminate an annoying completion you can take out the CompletionPrefix for any entry, or edit the code to be inserted to work how you like.

On a side note, you can put any file named .xctxtmacro and put it in that specifications directory and it will be read in, allowing you to define some very useful custom macros.

Lord Zsolt
  • 6,492
  • 9
  • 46
  • 76
Kendall Helmstetter Gelner
  • 74,769
  • 26
  • 128
  • 150
  • That looks promising. Will the original .xctxtmacro files in the `Xcode.app/contents` reappear when I upgrade Xcode later on down the line? – e.James Feb 08 '10 at 07:23
  • Yes, in fact you should not move them out of XCode, just copy them over into Specifications as any changes you make will override them... when you upgrade XCode you'll stll be overriding all those settings, but they don't change often. It would still be better to override specific entries that are bothering you and not override anything else (delete from the files you have in specifications). – Kendall Helmstetter Gelner Feb 08 '10 at 20:25
  • 1
    the PlugIns directory doesn't exist for me in xcode 4.5.2. has it moved? – Ben H Jan 11 '13 at 18:55
  • I just fixed the path, XCode is no longer in Developer... but PlugIns should be still there. – Kendall Helmstetter Gelner Jan 12 '13 at 05:13
  • And everything in that directory has extension `.ideplugin`. – Awesome-o May 19 '16 at 19:48
5

The "Text Editing" and "Indentation" preference sections might have the settings you seek.

You can set "Automatically suggest" to "never".

outis
  • 75,655
  • 22
  • 151
  • 221
  • A reasonable guess, but I haven't found anything in those panels that will affect the code completion. – e.James Feb 07 '10 at 22:58
  • Setting "Automatically Suggest" to "never" gets rid of *all* code completions, including variables and methods and all of that good stuff that I use on a regular basis `:(` – e.James Feb 07 '10 at 23:21
  • What about setting it to "with delay"? You can also use F5, alt-esc or "^," to get the completion list. – outis Feb 07 '10 at 23:43
  • I appreciate the suggestion. I've become so dependent on the instant auto-complete for variable and method names that even a short delay or another keystroke would drive me nuts. I just type something like NSDi without even thinking about it. I know I'm being picky here. My purpose in asking the question was to squeeze out the last 2% of extra productivity that could be had by fine-tuning. – e.James Feb 08 '10 at 01:03
  • I'm with you on not having a delay. I only suggested it because it would be less distasteful to you than switching to the 1TBS. Fortunately, it looks like the other question has a complete solution. – outis Feb 08 '10 at 01:21
5

You can enable/disable code completion in Xcode using below steps:

  1. Click on Xcode menu on top-left corner
  2. Select Preferences... (Preference Pop-up appears)

Screenshot-1 for steps

  1. Select Text Editing menu
  2. See Code Completion.
  3. Uncheck Suggest completion while typing option.

Screenshot-2 for steps

Jayprakash Dubey
  • 35,723
  • 18
  • 170
  • 177