1

FZF (fuzzy finder) is very convenient to find files by filename. However, I sometimes only know a function name or a part of the name. Is there a way to get FZF-like search, which would filter files by their content? git grep <pattern> command line command provides the functionality I want, but it works outside VIM.

Is there a way to get git grep search results inside VIM? It would be better to get real-time results like in FZF, when I type letters - the suggested file names change.

2
  • fzf.vim provides a :Rg command, I think this is what you are looking for. It uses rigrep. Check the link for setup suggestions.
    – Biggybi
    Feb 19 at 20:45
  • @Biggybi Wow, thats just great! Thats exactly what I was looking for :) Post this comment as an answer and will accept it.
    – niekas
    Feb 19 at 21:11
2

fzf.vim provides several commands suited for this task:

  • :Rg which uses ripgrep
  • :Ag which uses the Silver Searcher (ag)

These are external tools, they must be installed on the system (e.g. install ripgrep on a Debian based system:)

sudo apt install ripgrep

It is also possible to use fzf as a wrapper for gitgrep. The link above provides a Ggrep command to do so:


command! -bang -nargs=* GGrep
  \ call fzf#vim#grep(
  \   'git grep --line-number -- '.shellescape(<q-args>), 0,
  \   fzf#vim#with_preview({'dir': systemlist('git rev-parse --show-toplevel')[0]}), <bang>0)

Read more at :h fzf-vim. A list of fzf vim commands can be found under :h fzf-vim-commands.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.