views:

844

answers:

4

Say we have a TestClass with the 2 methods, -getSomeString and -getAnotherString, and we are editing the following code and the cursor is in the location shown:

NSString *aString = [TestClass get<cursorIsHere>SomeString];

Say I want to change it to use -getAnotherString. If I bring up the auto-completion popup and select the other method via hitting enter or tab, I'm left with:

NSString *aString = [TestClass getAnotherStringSomeString];

i.e., it doesn't replace the existing text but rather just inserts.

Is there a special keystroke to make it replace the remaining text?

See IntelliJ for reference.

A: 

I don't think so. I have always used the following

  • double click on getSomeString
  • press Escape (or your autocomplete key)
  • find replacement method

that double click step has never really bothered me, but I would be interested if anyone knows better!

adam
A: 

My work-around for this problem is this: Since the cursor will be right after the inserted text, I just press Shift-Option-Rightcursor, which selects the word past the cursor, then I hit the Delete key.

Thomas Tempelmann
+2  A: 

I don't think that there is a one step operation to achieve this. My suggestion would be similar to Thomas Templemann, but rather than two steps of forward word select and then Delete, I would expand to the desired autocomplete, by bouncing on Control + . and then hit Option + forward delete, which kills to the end of the word.

cms
A: 

You can use the Tab key to perform "replace" instead of "insert" when choosing the method from the auto-complete popup in IntelliJ 9 (don't know if it's available in previous versions).

Al
Yes, IntelliJ is fantastic - I've been using it for 6 years now. However, the question is whether you can do this autocomplete replacing in XCode.
nevster
Oops, looks like I got confused by the "See IntelliJ for reference" line in the question body (and didn't pay enough attention to the header/title). My apologies.
Al