reddit / emacs

projectile-replace-regexp equivalent in Evil mode

m-gregoire · 2022-09-21 14:47
Hello everyone, I'm an `evil-mode` user and I heavily rely on `:s/` to search and replace in a specific buffer interactively. I appreciate vim Regex style and the fact this is showing me the selection in real-time. However, when trying to do a search and replace project-wise, I'm often a bit lost. I'm aware of `projectile-replace-regexp` but this only works with Emacs style Regex (And cannot be changed AFAIK) and It's not showing the matches in real-time. I couldn't find a good way of making changes in the whole project using vim bindings in Emacs (Using projectile or not). Any idea on how to achieve this? Thank you for any help / recommendations to fix my workflow!
OgdenWebb · 2022-09-21 16:54
Check out occur and wgrep. You can grep matches in a project and then use occur or/and wgrep to edit them. Therefore using wgrep buffer you can call your normal ex commands from there. Tools like ivy/vectico+consult+embark/etc have some useful commands and keybindings to interact with occur/wgrep.
m-gregoire · 2022-09-22 09:17
Thanks a lot for your descriptive answer, It does indeed looks like what I'm looking for! I was able to do my search using `consult-ripgrep` and export it using `embark-export-write` then make my modifications with `:s/`. However, this doesn't work well with multi-line patterns. Let say I have the following: ``` my_array = [ "var1" "var2" ] ``` And I want to replace `var2` by `var3` across my project, but only if defined inside a `my_array` definition. Making this kind of regex requires using `rg` specific Regex (https://docs.rs/regex/latest/regex/#syntax). Is there any way of using vim regex for this initial search across the project? Thanks a lot EDIT: After reading Consult README, `consult-ripgrep` doesn't support `rg` regex, but Emacs one: > Always use Emacs regular expressions at the prompt. Ideally, I'd like to avoid having to remember the specificity of those different types of Regex and only stick with Vim ones.