LoginSignup
13
9

More than 5 years have passed since last update.

Emacsでディレクトリ以下の複数ファイルに対して一括置換する

Posted at

参考にしていたサイトがなくなってしまったので、こちらに掲載。

1. 対象ファイルを検索

M-x find-name-dired
Find-name (directory): ~/path/ (対象ディレクトリを入力)
Find-name (filename wildcard): * (ファイル名の検索パターンを入力。この場合は全部選択)

*Find*バッファに、対象ファイルの一覧ができる。

2. 対象ファイルを選択

t (toggle-mark)を押して全て選択。

3. 置換

Q を押す。
Query replace regexp in marked files: foo (置換される文字列を入力)
Query replace regexp in marked files foo with: bar (置換する文字列を入力)

置換箇所ごとにプロンプトが出るので、置換するならy、しないならnを入力。
全部置換するなら大文字でYを入力。

4. ファイルを保存

C-x s
! を押して全て保存。

refs. https://stackoverflow.com/questions/270930/using-emacs-to-recursively-find-and-replace-in-text-files-not-already-open

13
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
9