How can I find and replace inside a selection in Xcode?

This appears to be working again now, at least in Xcode 4.4.1.

When the find/replace bar appears at the top of the editor, holding down the option key on the keyboard causes "Replace in Selection" to appear in lieu of "Replace All."

I'm glad, because this was an ANNOYING omission.


Another workaround:

  1. In Xcode, select the text, press copy
  2. In a terminal session:

    pbpaste|sed 's/SOURCETEXT/NEWTEXT/g'|pbcopy
    
  3. Return to Xcode window, press paste

Since the original should still be selected, it will just be replaced. You could probably build a simple shell script to do this.

Doug


An few images to supplement the chosen answer:

enter image description here

enter image description here

And holding down Option:

enter image description here

See also

  • Find/Replace in Xcode using Regular Expressions

Seems like missing functionality. You should file a bug report.


I'm upset that they took out this functionality, as I used it constantly, but here's my workaround. Copy your selected text from Xcode4 to TextEdit or some other word processor, do the find and replace there, and then copy the results back into Xcode.

It's not sexy but it's worth it if you do a lot of these "find and replace on my selection", and you leave the word processor open in Spaces as you work.

They should add "my selection" as an alternative to "workspace" and "my scope".