0

I use fzf.vim (with rg) to search through (grep) my project.
The problem with this implementation is that (from what I understand) fzf.vim joins all the files (adding filename at the beginning of the line) and then fzf does the fuzzy search, so 'test' will find all the occurance of 'test' in all files but also will show all the lines from the file that have 'test' in its name (e.g. test.txt).

Is there a plugin/patch/etc that have grep (ag/rg etc.) that is lazy?
What I mean by that is:
Command is executed on type and there is delay to prevent executing command too frequently.

Best regards

  • Sorry, but I don't understand what you want. From the word "grep" I would recommend to read :help :vimgrep and :help :grep. – Ralf Jan 11 at 21:38
  • FZF runs asynchronously which means it will not block you. I do not know an option which sets a timedelay to wait after each keypress until fzf starts. I think this would contradict the mission of fzf being Blazingly fast. What is your actual problem with the current situation? Are you afraid that fzf when often used will use too much CPU which will extend running time of long-running tasks, shorten battery life, ...? – Hotschke Jan 12 at 7:01
  • What fzf.vim does is execute "grep" once (join all files) and then fuzzy search this one big buffer (this results in: 'test' will find all the occurance of 'test' in all files but also will show all the lines from the file that have 'test' in its name (e.g. test.txt) (because grep adds name of the file at the beginning of the line)). – droso Jan 12 at 17:17
  • I think I understand you now better. See here github.com/junegunn/fzf.vim/issues/714#issuecomment-428802659 and for :Ag here github.com/junegunn/fzf.vim/issues/346 – Hotschke Jan 13 at 14:53
0

Make :Rg match only file contents not file names

command! -bang -nargs=* Rg call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case ".shellescape(<q-args>), 1, {'options': '--delimiter : --nth 4..'}, <bang>0)

(from https://github.com/junegunn/fzf.vim/issues/714)

If you also want this for :Ag, add as well:

command! -bang -nargs=* Ag call fzf#vim#ag(<q-args>, {'options': '--delimiter : --nth 4..'}, <bang>0)

The author of fzf.vim junegunn recommends:

You should always try to provide an initial query to rg or ag and use fzf only as the secondary filter as it's much more efficient that way especially when your project is large.

  • Haven't tested yet but thanks, I hope It won't be much slower, cheers :) – droso Jan 14 at 17:55

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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