2010-11-19

emacs search and replace over multiple files

The built-in emacs search and replace facility is pretty great, but doing the same thing over multiple files is a bit of a pain.

There is a great package that makes it easy though: FindrPackage.

Install it using elpa package manager, but I had to do some manual adjustment of my .emacs file afterwards (not sure why the installer didn't automatically do this). The adjustments are documented under the heading "Installation" here.

One thing to note though. Findr's search and replace is interactive, so that's great. But the recursive find isn't obviously interactive, and after the first search result, you may be confused as to how to go to the next result. The key is to use the M-x tags-loop-continue command.

You may want to remap a key binding to make tags-loop-continue easier, by inserting into your .emacs file this line:

(define-key global-map [(meta ,)] 'tags-loop-continue)

Then a simple M-, after using Findr's search function will let you incrementally search for the next result in the files you indicated to be searched through.

No comments: