Tuesday, 02 June 2009

Emacs regexp replace in many files

  1. M-x find-dired
  2. Run find in directory: 'top directory to recurse'
  3. Run find (with args): -name *.[ch]
  4. A dired listing pops up
  5. Select/Mark all files, type: % m and press enter
  6. M-x dired-do-query-replace-regexp
  7. Query replace regexp in marked files: 'seach regexp'
  8. Query replace 'NNN' with: 'replacement text'
  9. You will now be prompted for each file with a math to do replace, just like you would a regual M-C-% search.

Note: regexp back references are allowed in the replacement text.

posted at: 14:44 | path: /emacs | permanent link to this entry