Sublime Text

How to Replace Text in Sublime Text Fast

How to Replace Text in Sublime Text Fast

Renaming 47 variables by hand is the kind of thing that makes developers switch careers.

Knowing how to replace in Sublime Text cuts that work down to seconds. The find and replace panel handles everything from basic text substitution in a single file to regex-powered batch replacements across an entire project directory.

This guide covers:

  • Single-file and multi-file replace workflows
  • Regex replace with capture groups
  • Multi-selection and cursor-based replacement
  • Every keyboard shortcut you need
  • Deleting matches with an empty replacement string

By the end, you will know exactly which method fits each situation, and which keyboard shortcuts to reach for first.

What Is the Find and Replace Function in Sublime Text?

maxresdefault How to Replace Text in Sublime Text Fast

The find and replace function in Sublime Text is a built-in text substitution tool that locates one or more string matches in a file or project directory and overwrites them with a specified replacement string. It lives inside the Find panel, which has 2 distinct modes: single-file replace and multi-file replace.

Sublime Text 4 (released May 2021 by Sublime HQ) supports the replace panel across all 3 platforms: Windows, macOS, and Linux. The panel layout contains a Find field, a Replace field, and 3 action buttons: Replace, Replace Next, and Replace All.

According to Capterra, Sublime Text holds an overall rating of 4.7 out of 5 stars based on 1,373 user reviews, with its search and replace options consistently praised. The tool works on the active buffer or across an entire project directory, depending on which panel mode you open.

If you’re comparing editors and want to understand how Sublime fits in the broader web development IDE category, it sits closer to a lightweight, fast text editor than a full IDE, which makes the replace workflow faster but less visual than heavier tools.

ModeScopeShortcut (Windows/Linux)Shortcut (Mac)
Single-file replaceActive buffer onlyCtrl + HCmd + Option + F
Multi-file replaceProject directory or folderCtrl + Shift + HCmd + Shift + H

How Do You Open the Replace Panel in Sublime Text?

maxresdefault How to Replace Text in Sublime Text Fast

The replace panel opens in 3 ways: keyboard shortcut, menu path, or by switching from the Find panel. The fastest method is the keyboard shortcut.

On Windows and Linux: press Ctrl+H. On Mac: press Cmd+Option+F. Both open the full replace panel directly, skipping the find-only panel.

The menu path is Find > Replace, which works on all platforms. Less convenient than the shortcut, but useful if you forget the key binding.

A common point of confusion: Ctrl+F opens the Find panel (search only), while Ctrl+H opens the Replace panel (search plus replacement fields). If you already have the Find panel open, you can switch to replace mode without closing it by pressing Tab to move focus or by using Ctrl+H to reopen it in replace mode.

How Does the Replace Panel Layout Work?

Panel fields, top to bottom:

  • Find field: enter your search string here
  • Replace field: enter the replacement string (can be left empty to delete matches)
  • Toggle buttons: regex (. button), case sensitivity (Aa), whole word (W)
  • Action buttons: Find, Replace, Replace All

The toggle buttons sit to the left of the Find field. Their state persists between sessions, so if you enabled regex last time, it stays enabled when you reopen the panel. Worth checking before running Replace All on a new file.

What Is the Difference Between Find and Replace in Sublime Text?

The Find panel (Ctrl+F) searches the active buffer and highlights matches. It does not modify the file.

The Replace panel (Ctrl+H) does everything the Find panel does, but adds a Replace field and 3 action buttons that write changes to the buffer. You can open both and switch between them without losing your search term.

How Do You Replace Text in a Single File?

maxresdefault How to Replace Text in Sublime Text Fast

Single-file replace targets the active buffer only. Open the replace panel with Ctrl+H, enter your search string in the Find field, enter the replacement in the Replace field, then choose Replace Next or Replace All.

Replace Next replaces one match at a time, moving the cursor to the next occurrence after each replacement. Use it when matches need individual review.

Replace All rewrites every match in the file in a single operation. Sublime Text highlights all matches in real time as you type in the Find field, so you can see how many instances will change before confirming.

How Do Case Sensitivity and Whole Word Options Affect Replace?

Both options are toggles in the replace panel. They change which strings count as matches.

ToggleButtonShortcutEffect
Case sensitiveAaAlt + CMatches exact case only
Whole wordWAlt + WPrevents partial matches

The whole word toggle is tricky. Searching “log” without it active matches “dialog”, “catalog”, and “log”. With it active, only the standalone word “log” matches. Both toggles are off by default when Sublime Text installs fresh.

How Does Undo Work After Replace All?

Replace All in a single file is fully reversible. Pressing Ctrl+Z (Cmd+Z on Mac) after Replace All restores every changed instance in a single undo step, not one step per replacement.

This differs from multi-file replace, where changes write directly to disk and undo behavior depends on whether the affected files are open in the editor at the time.

How Do You Replace Text Across Multiple Files in Sublime Text?

maxresdefault How to Replace Text in Sublime Text Fast

Multi-file replace uses the Find in Files panel. Open it with Ctrl+Shift+H on Windows/Linux or Cmd+Shift+H on Mac. The panel adds a “Where” field that controls which files Sublime Text searches.

The “Where” field accepts 4 input types: a folder path, open files, a file pattern (like .js), or a project scope. You can combine these with commas: <open files>,.html searches both open buffers and all HTML files in the directory.

What Happens When You Run Replace All Across Files?

Sublime Text writes changes directly to every matched file and reports results in the output panel at the bottom of the screen. The output lists each file path and the number of replacements made per file.

Key risk: files not currently open in the editor do not get an undo entry in memory. Changes to closed files write to disk immediately.

  • Open files: undo works normally with Ctrl+Z
  • Closed files: changes are permanent unless you use version control
  • Best practice: commit your changes to source control before running Replace All across a project directory

Teams using DevOps pipelines often treat large-scale text substitution across a codebase as a change that requires a commit diff review, not a silent file operation. Worth keeping in mind before running project-wide Replace All on 200 files.

How Does Multi-File Replace Differ Between Sublime Text 3 and 4?

Sublime Text 4 introduced improved tab multi-select and context-aware autocomplete, but the core Find in Files replace behavior is consistent across both versions.

Sublime Text 3: Find in Files output panel shows file paths and match counts. Replace writes to disk for closed files.

Sublime Text 4: Same core behavior, with a refreshed UI. The output panel formatting is slightly cleaner. Both versions use the same PCRE regex engine for pattern matching in the Where and Find fields.

How Do You Use Regex in Sublime Text Replace?

maxresdefault How to Replace Text in Sublime Text Fast

Sublime Text uses the Perl Compatible Regular Expressions (PCRE) engine from the Boost library for all regex operations in search panels, according to the official Sublime Text community documentation. Enable regex mode with the . button or the Alt+R shortcut before running any search.

With regex active, the Find field accepts full PCRE syntax. The Replace field supports capture group back-references using $1, $2 notation, which lets you restructure matched text rather than just delete or swap it.

If you want a handy reference while writing patterns, a regex cheat sheet covers PCRE syntax including quantifiers, anchors, character classes, and lookaheads.

Regex Replace Examples in Sublime Text

Reformat dates using capture groups:

  • Find: (d{2})/(d{2})/(d{4})
  • Replace: $3-$1-$2
  • Result: converts MM/DD/YYYY to YYYY-MM-DD

Strip HTML tags from text:

  • Find: <[^>]+>
  • Replace: (empty)

Replace double spaces with single space:

  • Find: (two spaces, or {2,} for 2 or more)
  • Replace: a single space

Always test your regex pattern with Replace Next before running Replace All. A mismatched capture group reference (like using $3 when only 2 groups exist) replaces text with a literal “$3” string, which is annoying to clean up.

How Do You Enable and Test Regex Mode?

Click the . button on the left side of the Find field, or press Alt+R. The button highlights when active.

Test the pattern by checking the match highlights in the file before committing. Sublime Text highlights all active matches in real time as you type in the Find field, which gives you a preview of scope before replacement. If the highlights look wrong, fix the pattern first.

How Do You Replace Text in Multiple Selections Simultaneously?

Multi-selection replace skips the replace panel entirely. Select a word, press Ctrl+D (Cmd+D on Mac) to add the next match to the selection, then type the replacement. All selected instances update at once.

The Sublime Text official documentation confirms that Alt+F3 on Windows/Linux (Ctrl+Cmd+G on Mac) selects every instance of the current word in the file in one step. This is faster than running Replace All from the panel when you need visual confirmation of every match location first.

When Is Multi-Selection Faster Than the Replace Panel?

Multi-selection wins in 3 scenarios:

  • Renaming a variable within a single file where you want to see all instances highlighted before changing
  • Small, localized replacements where opening the panel adds more friction than it saves
  • Cases where you want to skip specific instances (skip one with Ctrl+K, Ctrl+D on Windows)

The replace panel wins for bulk operations, regex-based substitution, and anything touching more than one file.

How Do You Skip a Match While Using Ctrl+D?

Pressing Ctrl+D adds the next match. To skip one and move to the next without adding it to your selection, press Ctrl+K, Ctrl+D on Windows/Linux (Cmd+K, Cmd+D on Mac). Sublime Text deselects the current match and jumps to the next occurrence.

This skip shortcut is one of the more underused features in Sublime. Most developers I’ve seen just use Ctrl+D repeatedly and then manually deselect by clicking, which wastes time.

How Do You Replace a Word Under the Cursor Across the File?

maxresdefault How to Replace Text in Sublime Text Fast

Place the cursor on any part of the word. Sublime Text selects the full word automatically when you press Ctrl+D (Cmd+D on Mac). Keep pressing to add each next occurrence to the selection, then type the replacement.

The Sublime Text official documentation confirms that when the cursor sits inside a word (not a manual text selection), Ctrl+D operates in full-word-only mode. This means “log” won’t accidentally match “dialog” or “catalog” as you add instances.

That behavior matters more than most people realize. Manual text selection plus Ctrl+D does partial matching, so selecting “foo” by hand and pressing Ctrl+D will also match “foobar”. Starting from a cursor position avoids that.

When to Use This Instead of the Replace Panel

Panel-free variable renaming works best for 3 specific scenarios:

  • Renaming a local variable within a single function or method
  • Quick label changes where you want visual confirmation of each match location
  • Files short enough that Alt+F3 (select all) gives a clear overview at once

The replace panel wins for anything touching multiple files, regex-based substitution, or files too long to review visually in one screen.

How Does Ctrl+D Differ from Alt+F3 for Word Replace?

Ctrl+D: adds one occurrence at a time. You control exactly which instances get selected before typing the replacement.

Alt+F3 (Ctrl+Cmd+G on Mac): selects every instance in the file at once. Faster for full-file renames, but gives no chance to skip individual matches.

Use Ctrl+D when instances need review. Use Alt+F3 when you’re confident all instances should change. Both approaches write replacements simultaneously once you start typing, with no panel, no Replace All button, no confirmation dialog.

What Are the Keyboard Shortcuts for Replace in Sublime Text?

maxresdefault How to Replace Text in Sublime Text Fast

All replace-related shortcuts in Sublime Text fall into 3 categories: opening the panel, toggling options, and navigating matches. The table below covers all of them across platforms.

ActionWindows / LinuxMac
Open Replace panelCtrl + HCmd + Option + F
Open Find in Files (multi-file)Ctrl + Shift + FCmd + Shift + F
Toggle regex modeAlt + RAlt + R
Toggle case sensitivityAlt + CAlt + C
Toggle whole wordAlt + WAlt + W
Select all occurrencesAlt + F3Ctrl + Cmd + G
Add next occurrenceCtrl + DCmd + D
Skip next occurrenceCtrl + K, Ctrl + DCmd + K, Cmd + D

The 2024 Stack Overflow Developer Survey showed VS Code used by 73.6% of professional developers, which puts Sublime Text in a minority position overall. But developers who do use Sublime consistently cite its shortcut system and multi-cursor editing as reasons they stay, according to Capterra reviews collected through mid-2024.

How Do You Customize Replace Shortcuts in Sublime Text?

Key bindings in Sublime Text use JSON files. Open Preferences > Key Bindings to edit them.

Example: always open Replace panel with regex pre-enabled:

{ "keys": ["ctrl+h"], "command": "showpanel", "args": { "panel": "replace", "regex": true } } `

Place this in the right-side User keymap file (not the default file on the left, which resets on updates). If you’re coming from a different editor, this is also where you remap shortcuts to match your existing muscle memory. Took me an embarrassingly long time to find this the first time.

Do Replace Shortcuts Differ Between Sublime Text 3 and 4?

No. The core replace shortcuts are identical across both versions. Sublime Text 4 (released May 2021) did not change any default key bindings for the find and replace panel.

Where versions diverge is in the UI rendering: Sublime Text 4 added hardware-accelerated rendering via OpenGL and native Apple M1 support, so the panel opens and highlights matches faster on modern hardware. The shortcuts themselves stayed the same.

How Do You Replace With a Blank String to Delete Matches in Sublime Text?

Leave the Replace field empty and run Replace All. Sublime Text treats an empty Replace field as a deletion instruction, removing every matched string from the buffer without inserting anything.

This is one of the most useful things the replace panel does that most developers figure out by accident. Common use cases:

  • Removing trailing whitespace from lines (Find: s+$ with regex on, Replace: empty)
  • Stripping HTML comments from a template file
  • Deleting commented-out code blocks across a file
  • Removing debug console.log() calls before a production push

The Trimmer package on Package Control extends this further, adding a dedicated command palette entry that trims trailing whitespace from every line on save, without needing to open the replace panel at all.

How Do You Delete Entire Lines Using Regex Replace?

Pattern to delete any line containing a specific string:

  • Find: ^.yourstring.n (with regex on)
  • Replace: (empty)

The ^ anchors to the start of the line. The . matches any characters before and after the target string. The n at the end removes the newline character too, so you don't end up with blank lines where the deleted lines were.

If your file uses Windows line endings (CRLF), use rn at the end instead of n. Worth checking in the bottom status bar before running the regex. Mismatched line endings are a common reason the pattern "works" but leaves empty lines behind.

Replace vs Delete: Choosing the Right Approach

Both do text removal, but they work differently in scope and reversibility.

Replace with empty string: best for pattern-based removal across an entire file or project, reversible with Ctrl+Z for open files.

Delete key after multi-selection: best for targeted removal of specific instances you’ve confirmed visually with Ctrl+D or Alt+F3.

For large-scale cleanup before a commit (removing debug logs, stripping comments, normalizing whitespace), the replace panel with an empty replacement field combined with a good code review process is faster and more auditable than manual deletion. If you are doing this type of cleanup regularly, it is also worth knowing how code refactoring fits into that workflow at a broader level.

For a quick reference while working with patterns, the regex cheat sheet covers anchors, character classes, and quantifiers that come up often in deletion patterns.

If you want to see how Sublime Text compares to other editors on find-and-replace and general workflow, the VSCode vs Sublime Text breakdown covers both in detail, including the find and replace workflow in VSCode if you use both editors in parallel.

FAQ on How To Replace In Sublime Text

What is the keyboard shortcut to open the replace panel in Sublime Text?

Press Ctrl+H on Windows and Linux. On Mac, use Cmd+Option+F. Both open the full replace panel with Find and Replace fields ready. The menu path Find > Replace works on all platforms if you prefer it.

How do I replace all instances of a word in Sublime Text at once?

Open the replace panel with Ctrl+H, enter your search string and replacement, then click Replace All. Sublime Text rewrites every match in the active buffer in one step. Press Ctrl+Z immediately after to undo all changes at once.

Can I replace text across multiple files in Sublime Text?

Yes. Use Find in Files, opened with Ctrl+Shift+F. Enter your search term, replacement string, and target folder in the “Where” field. Click Replace All. Changes write directly to disk for files not currently open in the editor.

How do I use regex to replace text in Sublime Text?

Enable regex mode by clicking the . button or pressing Alt+R. Sublime Text uses the PCRE engine from the Boost library. Use parentheses for capture groups in the Find field and $1, $2 notation in the Replace field.

How do I replace a word under the cursor without opening the replace panel?

Place the cursor on the word and press Ctrl+D repeatedly to select each next occurrence. Type the replacement once all target instances are selected. Press Alt+F3 to select every occurrence in the file at once.

How do I make the replace function case sensitive in Sublime Text?

Toggle the Aa button in the replace panel, or press Alt+C. With case sensitivity on, “Text” and “text” are treated as different strings. The toggle is off by default each time Sublime Text is freshly installed.

How do I replace only whole words in Sublime Text?

Click the whole word toggle (W button) in the replace panel, or press Alt+W. This prevents partial matches. Searching “log” with whole word on will not match “dialog” or “catalog”, only the standalone word.

How do I delete text by replacing it with nothing in Sublime Text?

Leave the Replace field empty and run Replace All. Sublime Text removes every matched string without inserting anything. This works for stripping trailing whitespace, removing HTML tags, or deleting commented-out code blocks across a file.

What is the difference between Replace Next and Replace All in Sublime Text?

Replace Next substitutes one match at a time, moving the cursor to the next occurrence after each change. Replace All rewrites every match in the file instantly. Use Replace Next when individual matches need review before committing.

How does Sublime Text replace differ from find and replace in VSCode?

Both use similar panel layouts and support regex, case sensitivity, and whole word matching. Sublime Text is faster on large files due to its lighter architecture. For a full breakdown, the Sublime vs PyCharm and Sublime vs Notepad++ comparisons cover workflow differences across editors in detail.

Conclusion

This conclusion is for an article presenting every core method for text substitution in Sublime Text, from the basic replace panel to project-wide batch replacement across multiple files.

The replace panel handles most situations. For pattern-based work, the PCRE regex engine with capture groups covers everything from reformatting dates to stripping unwanted code.

Multi-cursor editing with Ctrl+D and Alt+F3 is the faster path for single-file variable renaming. No panel needed, no Replace All confirmation, just type.

Deleting matches with an empty replacement string is underused. Trailing whitespace removal, comment stripping, cleaning up debug logs before a commit, all of it runs through the same workflow.

Pick the method that fits the scope of the task. The shortcuts are worth memorizing.

50218a090dd169a5399b03ee399b27df17d94bb940d98ae3f8daff6c978743c5?s=250&d=mm&r=g How to Replace Text in Sublime Text Fast

Stay sharp. Ship better code.

Every week: one curated article, one tool worth knowing, one tip you can use tomorrow. No noise, no padding.