views:

65

answers:

2

Possible Duplicate:
Using Emacs to recursively find and replace in text files not already open

I am using emacs and want to replace a word (well, all functions called foo() to foobar()) for all occurrences in a directory of source files. What is the best way to do this?

A: 

From the shell:

sed -i 's/foo\(/foobar\(/g' *.c *.h

this will replace all instances of foo( with foobar(.

Burton Samograd
+2  A: 

Burton's answer is as easy as it gets. Here's one way to do it in Emacs:

M-x dired fill in the directory you want to work in

* s marks all files in the directory

Q runs query-replace-regex on all marked files. Fill in the search regex and the replace string.

Type ! to replace all occurrences in each file. You will have to go back to save the changes though.

Hofstad
You can also get a dired buffer of a directory by just opening it with `find-file`, too. `M-x find-dired` if you want to include files in subdirectories as well.
ataylor