Find and Replace
This page is about finding in one document. To search a whole project, see Project find and replace.
- Finding
- Search options
- Replacing
- Doing more with the matches
- Recent and saved searches
- Regular expressions
Finding
Choose Edit ⟩ Find ⟩ Find… (command F) and the find bar opens above the editor. Type what you are looking for: the matches are marked in the text as you type, and the bar says how many there are.
Move between the matches with the arrows in the bar, or with Edit ⟩ Find ⟩ Find Next (command G) and Find Previous (shift command G). Click Done to close the bar.
To search for text that is already in your document, select it and choose Edit ⟩ Find ⟩ Use Selection for Find (command E), then use Find Next. Jump to Selection (command J) scrolls back to wherever the selection is.
Search options
Four buttons in the find bar change how a search is made:
- Regular Expression: what you type is a pattern, not literal text
- Matching Case: capitals and small letters must match. Without it, "nav" also finds "Nav".
- Whole Words: "nav" does not find "navigation"
- In Selection: the search is kept to the text that was selected when you turned this on, which is tinted so you can see where the search ends. It is turned off again when the find bar closes.
Replacing
Choose Edit ⟩ Find ⟩ Find and Replace… (option command F) to open the find bar with a second row for the replacement.
- Replace replaces the match that is selected in the editor
- All replaces every match. When In Selection is on it reads All in Selection.
- Edit ⟩ Find ⟩ Replace and Find replaces the selected match and moves on to the next one, so that you can go through a document deciding on each
Doing more with the matches
- Edit ⟩ Find ⟩ Select All Matches (control command G) selects every match at once. Whatever you then type is typed at all of them: see Multiple selections.
- Edit ⟩ Find ⟩ Extract Matches makes a new document that lists every match, one to a line. If you have filled in a replacement, each match is written as its replacement would be, which with a regular expression lets you pull one part out of every match: every link's address, say, or every class name.
Recent and saved searches
Click the magnifying glass in the search field for a menu of your recent searches. To keep a search, choose Save Search… from the same menu and give it a name. A saved search remembers its options and what it replaces with, and is listed under the magnifying glass in every find bar.
Regular expressions
With Regular Expression on, what you type is a pattern, and the parts of a match that you put in parentheses are available in the replacement as $1, $2 and so on, with $0 for the whole match.
If you are new to regular expressions, you might find regular-expressions.info a useful introduction and reference.
Espresso uses the Oniguruma syntax, as Ruby does, which has all the standard features you would expect (capture groups, character classes, lookahead and lookbehind, and so on). For those familiar with other flavors, the main difference is that the option for "dot matches newlines" is m, where most others call it s: (?m) at the start of your expression lets . match a line ending, and (?-m) stops it.