Writable grep buffer and apply the changes to files
Emacs Lisp
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 103 commits behind mhayashi1120:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



wgrep allows you to edit a grep buffer and apply those changes to the file buffer.


Put this file into load-path'ed directory, and byte compile it if desired. And put the following expression into your ~/.emacs.

(require 'wgrep)


You can edit the text in the grep buffer after typing C-c C-p. After that the changed text is highlighted. The following keybindings are defined:

  • C-c C-e: Apply the changes to file buffers.
  • C-c C-u: All changes are unmarked and ignored.
  • C-c C-d: Delete current line (including newline). This is immediately reflected in the file's buffer.
  • C-c C-r: Remove the changes in the region (these changes are not applied to the files. Of course, the remaining changes can still be applied to the files.)
  • C-c C-p: Toggle read-only area.
  • C-c C-k: Discard all changes and exit.
  • C-x C-q: Exit wgrep mode.

To save all buffers that wgrep has changed, run

M-x wgrep-save-all-buffers

You can change the default key binding to switch to wgrep.

(setq wgrep-enable-key "r")

To apply all changes wheather or not buffer is read-only.

(setq wgrep-change-readonly-file t)


This program is a forked version. the original version can be downloaded from http://www.bookshelf.jp/elc/grep-edit.el

Following added implementations and differences.

  • Support GNU grep context option -A -B and -C
  • Some bugfix. (wrong coloring text etc..)
  • wdired.el like interface.
  • Remove all advice.
  • Bind to local variables. (grep-a-lot.el works well)
  • After save buffer, colored face will be removed.
  • Change face easy to see.
  • Reinforce checking error.
  • Support removing whole line include new-line.