emacs_tutorial/doc/replace_text_mutiple_files.org

1.5 KiB

Replace text in multiple files using dired

Sometimes you may need to replace words or sentences across multiple files. That operation could be bore, since you will need to open, replace and close multiple files.

Emacs has options to deal with that situation using dired. Let's say you need to replace the word "code language" in multiple files within a directory.

You may follow this steps:

  • Open the directory using dired:

    • Use the keys1 C-x d
  • Mark all the files where you need to make the replacement

    • You may press the key "m" over each name of the files
    • Optionally press "t" to mark all files
  • Then you may use M-x dired-do-find-and-replace 2
  • After this you will present with multiple occurrences of the text you will replace.

    • You may replace all the occurrences within a buffer using "!"
    • You may also check every occurrence and use backspace or "y" to make a replacement by each occurrence
    • You may use "n" if you don't want to make any specific replacement
    • I you have doubts about this point, you can use '?' at the moment of make the replacement to display additional information on how to use this tool

References

Footnotes


1

i.e., press "Control" and "x" keys, then, press "d" in the keyboard

2

i.e., press the key "Alt" and "x", then write the instruction. You may press also the key "Q"