1

I am using ripgrep as external grep program in neovim. Which works when I call :grep 'pattern' in neovim Command Mode.

I frequently have to search some strings within a blocked range in long json files (i do not want to search the entire file but only within a range).

I would love to know,

  1. If it is possible to use vim :grep with range ?
  2. How can I use :grep 'pattern' % to search with a visually selected range only in the given file and not the entire file ?

I tried 15,82grep '^\s{8}\w+' % but it does not respect the range provided and searches the pattern with in the entire files !!

2
  • 2
    :grep does not work with range. It calls an external program and parses the output into the quickfix list. If I'm not mistaken, you want to pipe the visually-selected text to ripgrep and put the results in the qflist, right? That can be achieved by a custom function. But not by the standard :h :grep and :h gp system.
    – 3N4N
    Commented Sep 26, 2022 at 19:50
  • Cross-posted here: reddit.com/r/vim/comments/xosfpb/…
    – r_31415
    Commented Sep 26, 2022 at 20:12

1 Answer 1

1

Vim/Neovim internal :vimgrep works for me.

:vimgrep /^\%V\s\{8}\a\+/ %

All results are places in quickfix list, grep search results respects the given visual range provided.

Cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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