Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

replace

xcode

In Xcode < 4, you could hold the "option" key, and the "Replace All" button would change to "Replace in Selection". As of Xcode 4, this does nothing. Anyone know if there's a new way to do it, or is it bug filing time?

like image 606
DougW Avatar asked Mar 10 '11 02:03

DougW


People also ask

How do I find and replace in Xcode?

Click on 'Find' (in the search navigator) and choose 'Replace' from the dropdown.

How do you replace all words in Xcode?

Xcode displays the results of the search, but it doesn't automatically replace the text. To replace the text for a single result, select it and click the Replace button. To replace the text for all results, click Replace All.

How to search entire Xcode project?

To find text in a file, open the file in the Xcode source editor and choose Find > Find from the menu bar. Xcode displays the Find bar and its search controls at the top of the file. Enter a search term. Xcode searches the file, highlights matches, and notes how many it finds.


2 Answers

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.

like image 60
Lou Alicegary Avatar answered Sep 22 '22 03:09

Lou Alicegary


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

like image 39
Doug Sjoquist Avatar answered Sep 21 '22 03:09

Doug Sjoquist