Is there a way to configure the Vim grepprg parameter to avoid waiting until the external tool completes the search?

I am a long wimmer. However, I continue to go into the shell to do the search. This allows me to use the functionality of quickfix.

The main reason for switching to the shell is that when I use grep from inside Vim (with :grep ), I cannot follow the progress.

Since the code base I'm looking for is usually wide, I really appreciate the immediate feedback.

This gives me the opportunity to find out that my search expression is incorrect before the full results are displayed.

This allows me to cancel the search, refine the expression, and restart the search.

Any hint on how to reproduce this template inside Vim would be appreciated.

+8
vim grep
source share
5 answers

I do not see the same vim behavior as you. When I run :grep , I still see the results in vim (not in quickfix) until the search is complete (but I cannot do anything until the search is done).

I even tried using vim vim settings or plugins:

 gvim -u NONE -U NONE 

If this is not your behavior, check grepprg . Default value:

 :verbose set grepprg grepprg=grep -n $* /dev/null 

When I use run grep -e "score" -R /etc , I see this output in vim:

 :!grep -n -e "score" -R /etc /dev/null 2>&1| tee /tmp/voLcaNS/232 

Your system may be missing tee , or your vim is not using it (I use Vim 7.2 on Ubuntu 10.10). tee transfers the text passed to it and writes it to a file and to standard output.


If you are looking for a way to update quickfix with search results and you do not have a lock during the search, then you can write a script that:

  • looks for grep as a background process and redirects the file.
  • every second until grep finishes, vim uploads the file to quickfix ( cgetfile ) (you can tell vim to do something from another process with --remote-expr )

You can try my AsyncCommand plugin to run your code. It does this, except that it only downloads the file after the search is complete.

+1
source share

Are you familiar with ack.vim ? It does not use the quickfix window, but uses a separate buffer in the split. However, it is rather faster results returning to the vim frame.

+1
source share

Take a look at :vimgrep in the online documentation. It displays the searched file name and updates it.

0
source share

This may be caused by buffering between grep and tee , not vim. To test this theory, run grep from the command line and push the output through tee (i.e. grep <pattern> <files> | tee temp.out ). If it behaves the same as in vim, then buffering occurs.

To get around, install expect ( sudo apt-get install expect-dev on Ubuntu 10.10) and grepprg on unbuffer grep -n $* /dev/null . (See Turn off buffering in the handset ).

0
source share

There are three ways to search in all projects.

  • Grep system command (fast but not working with Ouickfix list)

     =>$ grep -n Example * 
  • Vim internal grep (slow but strong template support)

     :vim[grep] /{pattern}/[g][j] {file} ... 
  • Ack system plugin (excellent)

    1 install ack

     brew install ack 

    2 add below configs to your .vimrc

     :set grepprg=ack\ --nongroup\ --column\ $* :set grepformat=%f:%l:%c:%m 

    3, then you can use grep to call ack in vim, for example

     :grep "object\." app/**/*.rb 
0
source share

All Articles