Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Sublime Text Finds and Replaces


May 24, 2021 Sublime Text Use the manual


Table of contents


Find and Replace (Finding and Replacing)

Sublime Text provides powerful lookup (and replace) capabilities, and to provide a clear introduction, I've divided Sublime Text's lookup capabilities into three types: quick lookup, standard lookup, and multi-file lookup.

Quickly find and replace

In most cases, we need to find another location where a keyword appears in the text, then we don't need to re-enter the keyword and search, we just need to select the keyword using Shift ←/→ or Ctrl s D, and then F3 jumps to its next appearing position, Shift plus F3 jumps to its previous appearing position, and we can select all the locations that appear with Alt s F3 (after which we can make multiple edits, that is, quickly replace it).

Sublime Text Finds and Replaces

Standard lookups and replacements

Another common use scenario is to search for keywords in a known but not currently displayed area, where you can use Ctrl and F to call up the search box:

Sublime Text Finds and Replaces

and replace it with Ctrl and H:

Sublime Text Finds and Replaces

Keywords lookups and replacements

For the average user, a regular keyword search meets their needs: After entering the keyword in the search box, Enter jumps to the next position of the keyword's current cursor, Shift-Enter jumps to the previous location, and Alt-Enter selects all the locations where it appears (again, you can quickly replace it).

Sublime Text looks in different modes: Case-sensitive (Case-sensitive) mode for Alt-C switching, Alt-W switching for whole-word matching mode, and in addition to Sublime Text, which supports search in the selected range, this feature does not have the corresponding shortcuts, but can be turned on automatically with the following configuration items.

"auto_find_in_selection": true

This way, the search Chinese within range of the selected book is automatically turned on, and with this feature, local renaming becomes very convenient:

Sublime Text Finds and Replaces

For standard substitution using Ctrl-H, after entering the replacement, replace the current keyword with Ctrl-Shift-H, and Ctrl-Alt-Enter replace all matching keywords.

Regular expressions look for and replace

Regular expressions are a very powerful text-finding and replacement tool, and Sublime Text uses Alt-R to switch regular matching mode on/off. Sublime Text uses the Perl regular expression style in Boost.

For space reasons, this article does not detail regular expressions, and Mastering Regex (Chinese translation: proficient in regular expressions) details the principles of regular expressions and their use in each language. There are also a number of great tutorials on regular expressions online ("30-minute getting started with regular expressions" and MSDN regular expression tutorials .aspx) as well as online testing tools (regexpal and regeexer).

Multi-file search and replacement

Turn on multi-file search and substitution using Ctrl and Shift and F (note that this shortcut conflicts with the simple toggle shortcuts of the Sogou input method):

Sublime Text Finds and Replaces

Multi-file search and replace the default is to search/replace files and folders that are currently open, and we can also specify files/folders to search/replace.