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:

  1. keyboard shortcuts: Hit Ctrl + F (or Cmd + F on your Mac)
  2. the Command Palette, by running the Editor: Search in Editor command
  3. clicking the Search button below the open file tabs in the editor

Search and Replace prompt screenshot

Searching using plain text

To search for a plain piece of text in the file you are currently editing:

  1. open the Search and Replace prompt
  2. type the text you would like to search for, in the first input field

Screenshot of found text

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:

  1. open the Search and Replace prompt
  2. type the your regular expression using literals syntax (e.g. /^\d/ to search for numbers at the beginning of lines)

Screenshot of matched text

Notes

  • You do not have to hit Enter to perform a search!

Replacing text

To replace text in the editor:

  1. do a search either via text or regular expression
  2. type the text to replace the matches in the second input field
  3. replace: a. the current match (hit Enter or click on One) a. all matches (hit Shift + Enter or click on All)

Screenshot of replace form

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:

  1. search using a regular expression with parenthesized substring matches (e.g. /\*\*(.+)\*\*/ to search for text inside double asterisks) Search and Replace with regex prompt
  2. 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 with strong HTML tags, while keeping enclosing text) Search and Replace with regex result