💾 Archived View for g.codelearn.me › 2017-10-20-projectile-search-replace.gmi captured on 2023-06-16 at 16:25:59. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
Projectile is great Emacs package you definitely have to install if you didn't.
Along with projects management and quick switching among of them it allows you to limit grep/ack, find files and replacing commands. Here I want to note how to quickly search and replace strings in your project.
If you know basics of `grep` you shouldn't get any issues with it. Just call `projectile-grep` interactive function and type the query.
Here is how it works on this blog with `title:` query:
As you can see there is new buffer created called `*grep*`. At the bottom it says that search is finished (`:exit`) and have matches (`[matched]`). Filenames are links, so you can click on them and file will be opened in new buffer on the matched line.
Projectile is also really great in replacing with its `projectile-replace` and `projectile-replace-regexp`. When you call one of those functions you will be asked for an input to search for. Let's search the blog for `Replace`. When you typed the query, you need to input the string you want to replace on. Let's replace our `Replace` with `Find`.
When both params are entered the buffer with first match will be opened.
You can see the info in the mini-buffer:
Now you can press some keys to perform actions. Press `?` for help.
As you can see if you click `y` button then the replace action will be performed. If you see something wrong is going to be replaced just press `n` button to skip the currently highlighted match and Emacs will switch to the next match.
Searching and replacing should be used as often as possible with minimum of manual work. It will save you from mistakes and improve your productivity a lot.
Good luck <3