How do you type text in Xcode?

Stupid question: how are you supposed to type text in Xcode and get the result you expect?


Example 1:


Let's say I have the following line of code:


[someDictionary objectForKey:@"myKey"];


I want to switch to "someDictionary[myKey"];" so:


1. I delete the first '[' -> it works.

2. I select " objectForKey:" and press the '[' key.


I get:


someDictionary[ objectForKey:]@"myKey"];



Sigh.


Example 2:


I have the following lines of code:


if (something==anotherthing)

{

doSomething();

}


I want to remove the {} so:


1. I select "{

" and press the tab key.


I get:


if (something==anotherthing)

{

doSomething();

}


Sigh.


It's as if the Xcode text editor had been replaced with the Dev Forum text editor.


Question:


How are you supposed to type text in Xcode and get the result you expect?


I checked the Text Editing > Editing options, tried to disabled a few of them that could be connected to this issue but it didn't solve these 2 annoying issues.


Xcode 11.0 or 11.1.

Accepted Reply

Go to Preferences -> Text Editing -> Editing tab, and uncheck "Enclose selection in matching delimiters". The one Claude mentioned is for something else. FWIW, I hate the "Enclose selection matching delimiters" behavior, because it makes editing different from every other text editing experience. However, if you truly wanted it, you would have to remember to press Delete before pressing any (, [, etc opening delimiter key.


For the second problem, that's the new standard behavior. You can change this at Preferences -> Text Editing -> Indentation table, by changing the "Tab Key:" popup. It's possible, though, that none of the choices is exactly what you are used to. You can also explore remapping the Tab key to a different Xcode function, in Preferences -> Key Bindings.

Replies

I don't know if you've tried those settings:


Example 1:


When you select text and type [, XCode automatically inserts a closing matching ].
But you can change this behavior:

XCode > Preferences

Select Text Editing tab

Select Editing at top of the panel

Here you can unmark "Automatically balance brackets in Objective-C methods calls


Example 2


Same for "Automatically insert closing braces"

I tried switching these 2 checkboxes: it does not make any difference.


And in previous versions of Xcode (e.g. 6, 7, 10) , they were enabled and I didn't see this issue in the source editor.

Go to Preferences -> Text Editing -> Editing tab, and uncheck "Enclose selection in matching delimiters". The one Claude mentioned is for something else. FWIW, I hate the "Enclose selection matching delimiters" behavior, because it makes editing different from every other text editing experience. However, if you truly wanted it, you would have to remember to press Delete before pressing any (, [, etc opening delimiter key.


For the second problem, that's the new standard behavior. You can change this at Preferences -> Text Editing -> Indentation table, by changing the "Tab Key:" popup. It's possible, though, that none of the choices is exactly what you are used to. You can also explore remapping the Tab key to a different Xcode function, in Preferences -> Key Bindings.

For the second problem, "Insert tab character" is the behavior I'm looking for.


Thanks.