How to Find and Replace in Sublime Text 3

Sublime Text 3 has two built-in find and replace functions, one for searching in a single file and another for searching multiple files in a directory. Both provide simple text, case-sensitive, whole word and RegEx matching.

 

In this tutorial, we will go through how to find and replace single and multiple matches with Sublime Text 3.

 

Find and Replace all Matches in a File

to find and replace all matches in a single file, press the key combination CMD + OPT + F on macOS and CTRL + ALT + F on Windows and Linux.

 

opening console

 

This will open the Find and Replace Console at the bottom of the window. Type the phrase to match in the first input and what to replace it with in the second.

 

You can then click the "Find" button to cycle through each match and decide which individual matches to replace or click the "Replace All" button to replace all matches at once.

 

Find

 

Find and Replace all Matches Across Multiple Files

To find and replace matches across multiple files, right-click on the folder to scan in the project sidebar and click the "Find in Folder..." option. This will open the Find in Files console at the bottom of the window and preload the Where path with the folder you just selected.

 

 

Then type the phrase to search for in the first input and what to replace it with in the last.

 

Now you have the option to go ahead and replace all the matches at once by clicking the "Replace" button on the right or open a new Find Results tab containing a list of all the matches.

 

If you opened the Find Result tab, you can double click any of the match excerpts and Sublime will open the file and take you to the line where the match was found.

 

 

Regex Find and Replace

To enable RegEx pattern matching in Sublime Text, click on the .* button on the far-left hand side of the find console window. Alternatively, you can use the key combination CMD + OPT + R on macOS and CTRL + ALT + R on Windows/Linux while the console is the active window.

 

RegEx option

 

Now you can type a regular expression in the find input. Here is an example that will look for any line that doesn't contain the phrase "hello" and replace the whole line with nothing.

 

^(?!.*hello.*).+$

 

Case Sensitive Matching

To enable case sensitive matching in Sublime Text click the Aa button on the left-hand side of the find console window. Alternatively, you can use the key combination CMD + OPT + C on macOS and CTRL + ALT + C on Windows/Linux while the find console is the active window.

 

Case senstive

 

Whole Word Matching

To enable whole word matching, press the “” button on the left side of the find console window or use the CMD + OPT + W key combination on macOS and CTRL + ALT + W on Windows/Linux.

 

Whole word
sublime