11

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?

Samselvaprabu
  • 16,830
  • 32
  • 144
  • 230

2 Answers2

9

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>
Riza Khan
  • 2,712
  • 4
  • 18
  • 42
3

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

romainl
  • 186,200
  • 21
  • 280
  • 313