The easiest way to search and replace across multiple files in emacs

Use ‘M-x find-grep-dired’ interactively to search and replace a regex across all files in a specified directory and subdirectories which match a pattern.

As described in this blog post, basic usage is:

M-x find-grep-dired RET catch (FooException RET
    % m .php$ RET
    Q catch (FooException RET catch (BarException RET

At this point, Emacs will cycle through every match in every file and ask you to confirm the replacement. If you press !, it will replace the rest of the matches in the current file, and start prompting you for the next; Y will replace every match in every file with no further prompting. `M-,’ restarts the interactive prompting if you break out of it.

See DiredSearchAndReplace for more information.

See also DiredFindInLisp for ‘M-x find-grep-dired-lisp’.

CategoryDirectories CategorySearchAndReplace

 

Advertisements

One thought on “The easiest way to search and replace across multiple files in emacs

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s