0

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?

Community
  • 1
  • 1
Bain Markev
  • 2,795
  • 5
  • 24
  • 28

2 Answers2

2

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
  • 851
  • 7
  • 4
  • 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 Sep 20 '10 at 21:43
0

From the shell:

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

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

Burton Samograd
  • 3,504
  • 16
  • 20