- Published on
Persistent Search with Neovim and Telescope
- Authors
- Name
- Linell Bonnette
Persistent Search with Neovim and Telescope
Iāve been doing a lot of deep refactoring in SBLiveās biggest Rails codebase lately, and something thatās come up as noticeably missing from my Neovim setup, which is using Telescope.nvim for my file browser and searching, is the ability for me to see a persistent list of search results for whatever code Iām trying to refactor.
This is what Telescopeās live grep searching looks like ā itās pretty great. I can use the arrow keys to scroll through the results and the window on the right side shows a preview of that line within the file. Itās super useful for thing like finding every instance of .delay
in a codebase.
The problem is that as soon as I select one of the results, or as soon as I click on any other window, I lose those search results. Iāve got to redo the search and figure out where I was exactly within them all over again every time. I havenāt noticed this previously because 90% of the time thatās not a big deal at all and meshes well with how I write code.
Butā¦. Iāve got dozens of instances of .delay
in this codebase and itās so frustrating having to redo the same search dozens of times when what I really want is just to have a persistent list of the search results for me to look through at my leisure. I know other people want it too because itās come up more than once in Telescopeās issues:
- https://github.com/nvim-telescope/telescope.nvim/issues/310
- https://github.com/nvim-telescope/telescope.nvim/issues/1988
The best advice I really found online was this Reddit post that told me that Ctrl-q
puts all of the results in the quickfix list. That is almost exactly what I wantā¦ except the quickfix list seems to be sort of painful to interact with, and the time I spent trying to learn started feeling like a sunk cost so I moved on with life.
Then, this morning, I was hit by a silly little epiphany that Iām sure was mentioned on every page I encountered while searching for a solution:
- Open a new buffer.
:enew
- Put the search results in the buffer.
:%! rg --vimgrep '\.delay' .
Itās quick and easy, doesnāt require installing anything else, and I feel like a bit of a fool for having spent more than a few minutes being bothered by this problem in the first place.