emacs_tutorial/doc/replace_text_mutiple_files.org
2023-07-24 10:32:03 -03:00

1.2 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 using "!"
    • You may also check every occurrence and use backspace to make a replacement by each occurrence

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"