Search and Replace
SourceLair lets you search and replace text in the editor easily, using either plain text or regular expressions.
The Search and Replace prompt
You can access the Search and Replace prompt via:
- keyboard shortcuts: Hit Ctrl + F (or Cmd + F on your Mac)
- the Command Palette, by running the
Editor: Search in Editor
command - clicking the Search button below the open file tabs in the editor
Searching using plain text
To search for a plain piece of text in the file you are currently editing:
- open the Search and Replace prompt
- type the text you would like to search for, in the first input field
To navigate throughout the matched results:
- hit Enter to navigate to the next result
- hit Shift + Enter to navigate to the previous result
Notes
- You do not have to hit Enter to perform a search!
- You can also navigate to the next search term with Ctrl + G (or Cmd + G on your Mac)
- You can also navigate to the previous search term with Ctrl + Shift + G (or Cmd + Shift + G on your Mac)
- Text search is case insensitive, when the whole search term is lowercase
Searching using regular expressions
You can search for regular expression matches by using JavaScript Regular Expressions. To do this:
- open the Search and Replace prompt
- type the your regular expression using literals syntax (e.g.
/^\d/
to search for numbers at the beginning of lines)
Notes
- You do not have to hit Enter to perform a search!
Replacing text
To replace text in the editor:
- do a search either via text or regular expression
- type the text to replace the matches in the second input field
- replace: a. the current match (hit Enter or click on One) a. all matches (hit Shift + Enter or click on All)
Replacing with regular expression variables
A powerful feature of Search and Replace is the ability to search via regular expressions and replace with text that uses the matched terms as variables:
- search using a regular expression with parenthesized substring matches (e.g.
/\*\*(.+)\*\*/
to search for text inside double asterisks) - replace with text including dollar variables;
$1
for the first matched substring,$2
for the second etc. (e.g.<strong>$1</strong>
to replace the previous match withstrong
HTML tags, while keeping enclosing text)