As your code gets longer, you spend more and more time hunting for “that line I just wrote, where is it again?” And when you want to change every instance of a name to a different one, scanning from the top and fixing them one by one is a chore. That’s where Find and Replace come in.
First, “Find” — ⌘ + F / Ctrl + F
Press ⌘ + F and a small search box appears at the top right. Type the word you’re looking for and every instance lights up, along with a count of how many were found. Each time you press Enter, you jump to the next spot in order.
No more hunting with your eyes for “that class name” or “that character” in a long stretch of code.
The three icons to the right of the search box
At the far right of the search box, three small icons sit in a row. Pressing them toggles them on and off to narrow down how you search.
| Icon | Name | What it does |
|---|---|---|
Aa | Match Case | When on, treats Box and box as different things |
ab| | Match Whole Word | When on, matches box but no longer matches inbox |
.* | Use Regular Expression | Search by pattern (e.g., \d+ to find only numbers) |
Usually leaving them off is plenty, but when “I only want to find box, yet toolbox lights up too,” turning on Match Whole Word narrows it down to exactly what you’re after.
Next, “Replace” — ⌘ + ⌥ + F / Ctrl + H
Press the small > (arrow) to the left of the search box, and another input field opens below. That’s where your replacement goes.
- Top field: the word to find (e.g.,
box) - Bottom field: the new word (e.g.,
card)
Replace has two buttons.
| Button | What it does |
|---|---|
| Replace (one at a time) | Replaces just one found spot (with confirmation) |
| Replace All | Replaces every found spot all at once |
For example, to change the name box to card everywhere, one press of “Replace All” does it.
Replacing only within a selected range
“I only want to replace this part, but the whole file becomes the target.” When that happens, first select the range you want to replace, then turn on the “Find in Selection” icon at the far right of the search box.
Now, even if you press “Replace All,” nothing outside your selection is touched. Since you can safely aim at “just inside this function” or “just this block,” it’s the most practical answer to the “Replace All is scary” problem from earlier.
Replacing while preserving case
You want to change box to card, but your code also has Box (a class name) and BOX (a constant) mixed in—a common situation. A normal replace turns them all into lowercase card.
So turn on the AB icon to the right of the replace field (Preserve Case). Now the replacement keeps the original capitalization.
| Original word | After replace |
|---|---|
box | card |
Box | Card |
BOX | CARD |
Without knowing this, you’d have to go back and fix just the capitals by hand after replacing. It’s the option you’ll want to turn on first when renaming things.
Search across a whole folder (full-text search)
“I can’t remember which file I wrote it in!” For that, use the magnifying-glass icon (Search) on the left bar. ⌘ + ⇧ + F (on Windows, Ctrl + Shift + F) also opens it.
Type a word here and it searches all the files inside your open folder at once. It even lists which file and which line number, so you won’t get lost even on a site that’s grown large.
To replace across a whole folder, use ⌘ + ⇧ + H (on Windows, Ctrl + Shift + H). Here too, you don’t have to replace everything all at once. The list of search results can be replaced per file or per single item, and clicking a result line lets you check the difference between before and after.
Advanced: use $1 in regular expressions to reuse “what you found”
Turn on .* (regular expressions) in search, and you can reuse the part enclosed in () directly in the replacement. For example, when you want to standardize strings written with single quotes to double quotes:
- Search field:
'(.+)' - Replace field:
"$1"
Now a form like 'box' changes to "box". $1 means “the string that matched inside the parentheses.” It feels hard at first, but the day you face making the same small edit in dozens of places by hand, remembering this trick is a huge time-saver.
Summary
⌘ / Ctrl + Flights up and finds words within the current file- Turn on Match Whole Word to narrow down to exactly the word you want
- Use Replace to change the same word into another one in bulk
- Select a range and turn on Find in Selection to safely replace only there
- Turn on
AB(Preserve Case) andBoxbecomesCard, keeping upper/lower case - With
⌘ / Ctrl + ⇧ + Ffull-text search, find across every file in a folder at once
When finding and fixing gets faster, growing code stops being scary.