Fork me on GitHub

What do you all use for "project-wide search and replace"? I hacked something highly to my liking based on helm-ag back in 2017 (which worked with ag and rg alike). However that only works in Emacs 25 (or 26 sometimes), which I managed to keep using quite flawlessly until these days - now it's much less of a viable option. I reckon my requirements are simple: • Search project-wide, ideally honoring rg ignore rules or at least .gitignore • Preview each found match as a single line in some sort of UI • I can adjust my search query, and results/preview are updated real-time • Replace all occurrences with an input that is asked interactively, after I got to see the preview of the found results Ideas welcome!


deadgrep is awesome for "project-wide search", the replace part I still do manually 😄 Apparently it has (beta) which allows you to "edit files directly from results buffers" but I haven't tried it

👀 1

you can do that with vertico (interactive list) + consult-git-grep (project wide search, with live preview) + embark (to export the list in new buffer) + wgrep (edit results in buffer)

👀 1

sounds complicated but it's not

🌀 1

helm-ag works fine for me, usually coupled with iedit when editing the changes that are found. I havent needed anything more


I have ripgrep binary installed, so can use its filtering patterns in the initial search


consult can work with ag/rg/gitgrep/grep, you have the choice


in my experience git-grep gets the most relevant results and is often the quickest


Thanks! from what I remember, with vanilla helm-ag too many steps were involved, hence my tweaking which IIRC halved the involved steps. I really appreciate a 'streamlined' workflow which I can eventually master by muscle memory, I guess I can use vanilla helm-ag again, and tweak again the bits that seemed redundant. Hacking from scratch sure is more effective than reverse-engineering whatever I did 5y ago :)


doom-emacs uses vertico with ripgrep under the hood and it works amazingly well

👀 1

most of the modes from vertico author are really well done (consult, marginalia, corfu, etc), and they all compose nicely.

emacs 1

Nice! Do you have a search-and-replace wrapped under a defun or such? I'd be less enthusiastic about understanding/debugging each step from scratch


I just trigger consult-git-grep via a binding, the results show via vertico in the minibuffer, then once I am happy with the selection I trigger embark-export to get all the matches in a separate buffer via another binding and just edit the buffer contents, save, done


it's very quick


consult-git-grep + vertico is useful for other things, you can use that to navigate around, vertico will do a buffer preview as you go up/down the matches in the minibuffer


I use cousel-rg + ivy-occur (setting ivy-calling to t when I want to preview each search result's file and also allows me to do mass edit)