Emacs: Find Replace

By Xah Lee. Date: . Last updated: .

Interactive Find Replace

Alt+x query-replace

Emacs prompts you for the find string and replace string.

Once emacs found a match, press

To undo, exit it first, then do undo previous replacements one by one.

Interactive Find Replace Word with Boundary

Ctrl+u Alt+x query-replace

Find Replace All, in One Shot

Alt+x replace-string

Find Replace with Word Boundary, in One Shot

you want to change the word “red” to “blue”, but skip words containg “red” such as “redo”.

Ctrl+u Alt+x replace-string

Do find replace, with boundary check.

Find Replace, by Regex Pattern, in Current File

Reference

Emacs Find Replace