reddit / emacs

Is there a way to make wgrep work with git grep?

sweetyhoneybee · 2022-02-11 08:09
`wgrep` is a super useful mode, and combining it with `git grep` would be even much more of a game changer. Is there a way to make it work? Running `M-x grep` and then changing that command to use `git grep` instead of regular `grep` works for displaying the results, but when I do `wgrep-change-to-wgrep-mode`, it won't let me modify and save the results.
jpe-90 · 2022-02-11 10:32
I do something like this but with Ivy: * `counsel-rg` in a git repo, search for whatever * `ivy-occur` (C-c C-o) in the minibuffer - gives you all matches in an occur buffer * `wgrep-change-to-wgrep-mode`, make edits, save the buffer If you don't want to use helm/ivy, project.el (built in on Emacs 28 and later) will do repo-wide regex replacement with `project-query-replace-regexp` or, if you're on master, you can use `project-find-regexp` and then press R in the xref buffer to get prompted to replace results.
wargxs · 2022-02-11 19:43
Does vc-git-grep work? Otherwise [ack.el](https://github.com/leoliu/ack-el) supports git-grep and works with wgrep
wargxs · 2022-02-11 19:44
Excellent advise. Installing the latest version of project.el from elpa should also work to get the functionality you mention.
sweetyhoneybee · 2022-02-11 22:18
`vc-git-grep` seems to work out of the box, thanks!
sweetyhoneybee · 2022-02-12 10:41
This seemed to work, but it failed to work over TRAMP, which I also needed to use. Thanks for the suggestion!