Is it possible to display result of Rg into quick fix window?
Asked Answered
D

2

12

When i am searching :Rg <string> , it is opening the result in FZF buffer. Often the filenames are not displayed fully in it. Also the once escaped the results are gone. I have to do research if need to check the same word again.

but :vim /pattern/g **/* opens the result in quickfix. Is there any way to open Rg result in quickfix window? How to display the full file name in Rg buffer?

Dzungaria answered 27/10, 2020 at 10:36 Comment(0)
H
3

You can tell Vim what external command to use for :help :grep with :help 'grepprg'.

Herwig answered 27/10, 2020 at 11:8 Comment(7)
There is a confusion in adding grepprg. Whether this use Rg only for :grep command or also for :vimgrep command.Dzungaria
Only :grep is concerned by :help 'grepprg' but both :help :grep and :help :vimgrep have the exact same relationship with the quickfix list.Herwig
I don't understand this answer!Floorage
@RizaKhan what, specifically, do you not understand?Herwig
Nevermind I figured it out. I'll post an answerFloorage
@RizaKhan what was the answer? I have a very similar problem (I’d like to use FZF for search, but also be able to populate the quickfix list with the results)Louis
@Louis Here is what I use: set grepprg=rg\ -i\ --vimgrepTashinatashkent
F
12

I have my :Rg results open in a popover and that allows me to cycle through the results using <Ctrl>j and <Ctrl>k.

That is an individual selection though so if you want to save your results to a quick fix list, start by <Tab> and you will noticed a red indicator show up next to the name. Once you press enter everything with the indicator will be placed in the quick fix list.

enter image description here

enter image description here

I also wanted to mention my function for Rg

" Ripgrep advanced
function! RipgrepFzf(query, fullscreen)
  let command_fmt = 'rg --column --line-number --no-heading --color=always --smart-case %s || true'
  let initial_command = printf(command_fmt, shellescape(a:query))
  let reload_command = printf(command_fmt, '{q}')
  let spec = {'options': ['--phony', '--query', a:query, '--bind', 'change:reload:'.reload_command]}
  call fzf#vim#grep(initial_command, 1, fzf#vim#with_preview(spec), a:fullscreen)
endfunction

command! -nargs=* -bang RG call RipgrepFzf(<q-args>, <bang>0)

And I also wanted to add some shortcuts for quickfix list so that you can cycle through them easily:

map <leader>cc :botright cope<cr>
map <leader>co ggVGy:tabnew<cr>:set syntax=qf<cr>pgg
" Next item on list
map <leader>n :cn<cr>
" Previous item on list
map <leader>p :cp<cr>
Floorage answered 24/7, 2021 at 13:48 Comment(5)
The <tab> to select results from Rg to be put in quick-fix windows is a breeze!Damnable
Is there a way to save all results from Rg to the quickfix list?Louis
@Louis did you ever figure out how to save all results from Rg to quickfix list?Germin
@Germin not really; I’m using the tab key to add only selected results to the quickfix listLouis
@Louis @Germin You can use Alt-A to select all results (and Alt-D to deselect them), see the Commands section in the fzf.vim READMEArbitress
H
3

You can tell Vim what external command to use for :help :grep with :help 'grepprg'.

Herwig answered 27/10, 2020 at 11:8 Comment(7)
There is a confusion in adding grepprg. Whether this use Rg only for :grep command or also for :vimgrep command.Dzungaria
Only :grep is concerned by :help 'grepprg' but both :help :grep and :help :vimgrep have the exact same relationship with the quickfix list.Herwig
I don't understand this answer!Floorage
@RizaKhan what, specifically, do you not understand?Herwig
Nevermind I figured it out. I'll post an answerFloorage
@RizaKhan what was the answer? I have a very similar problem (I’d like to use FZF for search, but also be able to populate the quickfix list with the results)Louis
@Louis Here is what I use: set grepprg=rg\ -i\ --vimgrepTashinatashkent

© 2022 - 2024 — McMap. All rights reserved.