Search and Replace
Sublime Text features two main types of search:
Both support regular expressions, a powerful tool for searching and replacing text.
Single File
Searching
Keyboard shortcuts related to the search panel:
Description | Shortcut |
---|---|
Open search panel | Ctrl F |
Toggle regular expressions | Alt R |
Toggle case sensitivity | Alt C |
Toggle exact match | Alt W |
Find next | ⏎ |
Find previous | ⇧ ⏎ |
Find all | Alt ⏎ |
Incremental Search
Keyboard shortcuts related to the incremental search panel:
Description | Shortcut |
---|---|
Open incremental search panel | Ctrl I |
Toggle regular expressions | Alt R |
Toggle case sensitivity | Alt C |
Toggle exact match | Alt W |
Find next | ⏎ |
Find previous | ⇧ ⏎ |
Find all | Alt ⏎ |
The only difference between this panel and the regular search panel lies in the behavior of the ⏎ key. In incremental searches, it will select the next match in the file and dismiss the search panel for you. Choosing between this panel or the regular search panel is a matter of preference.
Replacing Text
Keyboard shortcuts related to the replace panel:
Description | Shortcut |
---|---|
Open replace panel | Ctrl H |
Replace next | Ctrl ⇧ H |
Replace all | Ctrl Alt ⏎ |
Tips
Other Ways of Searching in Files
Goto Anything provides the #
operator to search in the filtered file.
Other Search-Related Key Bindings
These key bindings work when the search panel is hidden:
Description | Shortcut |
---|---|
Search forward using most recent pattern | F3 |
Search backwards using most recent pattern | ⇧ F3 |
Select all matches using most recent pattern | Alt F3 |
You can also perform searches based on the current selection:
Description | Shortcut |
---|---|
Search using current selection | Ctrl E |
Replace using current selection | Ctrl ⇧ E |
Multiline Search
You can type in multiline search patterns into search panels. To enter newline characters, press Ctrl ⏎.
Note that search panels are resizable too.
Multiple Files
Searching
Keyboard shortcuts related to Find in Files:
Description | Shortcut |
---|---|
Open Find in Files | Ctrl ⇧ F |
Toggle regular expressions | Alt R |
Toggle case sensitivity | Alt C |
Toggle exact matches | Alt W |
Find next | Enter |
Search Scope
The Where field in Find in Files limits the search scope. You can define scopes in several ways:
- Adding individual directories (Unix-style paths, even on Windows)
- Adding/excluding files based on wildcards
- Adding symbolic locations (
<open folders>
,<open files>
...)
It is also possible to combine these filters using commas; for example:
Press the ... button in the search panel to display a menu containing scope options.
Results Format
In the search panel, you can customize how results are displayed. These are the available options:
- Show in separate view
- Show context
Navigating Results
If the search yields matches, you can move through the sequence using the following key bindings:
Description | Shortcut |
---|---|
Next match | F4 |
Previous match | ⇧ F4 |
Open match | ⏎ |
You can also double-click on lines with a match.
Regular Expressions
Regular Expressions find complex patterns in text. To take full advantage of the search and replace facilities in Sublime Text, you should at least learn the basics of regular expressions. In this guide we won't explain how to use regular expressions.
The term regular expression is usually shortened to regexp or regex.
This is how a regex might look:
(?:Sw|P)i(?:tch|s{2})\s(?:it\s)?of{2}!
To use regular expressions in Sublime Text, you first need to activate them in the various search panels. Otherwise, search terms will be interpreted literally.
Sublime Text uses the Perl Compatible Regular Expressions (PCRE) engine from the Boost library.
See Also
Boost library documentation for regular expressions : Documentation on regular expressions.
Boost library documentation for format strings : Documentation on format strings. Note that Sublime Text additionally interprets \\{n}
as ${n}
.