Skip to content

Commit

Permalink
Redirect stdin to null for the search command
Browse files Browse the repository at this point in the history
  • Loading branch information
yegappan committed Feb 25, 2018
1 parent f14caad commit a7a290b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
15 changes: 13 additions & 2 deletions autoload/grep.vim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
" File: grep.vim
" Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
" Version: 2.0
" Last Modified: Feb 20, 2018
" Last Modified: Feb 25, 2018
"
" Plugin to integrate grep like utilities with Vim

Expand Down Expand Up @@ -453,6 +453,11 @@ function! s:formFullCmd(cmd_name, useropts, pattern, filenames)
\ a:pattern . ' ' . a:filenames . ' ' .
\ cmdmap[a:cmd_name].nulldev

" Some commands like ripgrep try to read from stdin. This hangs the
" command as Vim controls stdin. To avoid this problem, redirect stdin to
" the NULL device.
let fullcmd = fullcmd . ' < ' . g:Grep_Null_Device

This comment has been minimized.

Copy link
@alvan

alvan Feb 27, 2018

This break the Rgrep command, I always get this error when searching:
Error: Pattern '...' not found
My vim version:
:version VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 6 2017 02:39:16) macOS version Included patches: 1-1272

This comment has been minimized.

Copy link
@yegappan

yegappan via email Feb 27, 2018

Author Owner

This comment has been minimized.

Copy link
@alvan

alvan Feb 27, 2018

Thank you for fixing this so quickly! It works fine now.


return fullcmd
endfunction

Expand Down Expand Up @@ -643,6 +648,12 @@ function! grep#runGrepSpecial(cmd_name, which, action, ...)
call s:runGrepCmd(cmd, pattern, a:action)
endfunction

" recursive_search_cmd
" Returns TRUE if a command recursively searches by default.
function! s:recursive_search_cmd(cmd_name)
return a:cmd_name == 'ag' || a:cmd_name == 'rg' || a:cmd_name == 'ack'
endfunction

" grep#runGrep()
" Run the specified grep command
function! grep#runGrep(cmd_name, grep_cmd, action, ...)
Expand All @@ -666,7 +677,7 @@ function! grep#runGrep(cmd_name, grep_cmd, action, ...)
echo "\r"
endif

if filenames == ''
if filenames == '' && !s:recursive_search_cmd(a:grep_cmd)
let filenames = input('Search in files: ', g:Grep_Default_Filelist,
\ 'file')
if filenames == ''
Expand Down
12 changes: 10 additions & 2 deletions doc/grep.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
For Vim version 7.0 and above
Last change: 2018 Jan 23
Last change: 2018 Feb 25

1. Overview |grep-overview|
2. Installation |grep-installation|
Expand All @@ -18,7 +18,7 @@ The grep plugin integrates the grep, fgrep, egrep, agrep, ag, ack and ripgrep
tools with Vim and allows you to search for a pattern in one or more files and
jump to them.

To use the this plugin with grep, you will need the grep, fgrep, egrep, agrep
To use the this plugin with grep, you will need the grep, fgrep and egrep
utilities. To recursively search for files using grep, you will need the find
and xargs utilities. These tools are present in most of the Unix and MacOS
installations. For MS-Windows systems, you can download the GNU grep and find
Expand All @@ -27,6 +27,11 @@ utilities from the following sites:
http://gnuwin32.sourceforge.net/packages/grep.htm
http://gnuwin32.sourceforge.net/packages/findutils.htm

If you want to use the agrep command with this plugin, then you can download
the agrep utility from:

https://www.tgries.de/agrep/

If you want to use the Silver Searcher (ag) with this plugin, then you can
download the Silver Searcher from:

Expand Down Expand Up @@ -167,6 +172,9 @@ commands. If the <file_names> are not specified, then you will be prompted to
enter file names. By default, the pattern specified by the
Grep_Default_Filelist variable is used. To specify the file name(s) as an
argument to the above commands, you have to specify the search pattern also.
For search utilities like ag, ack and ripgrep which searches recursively by
default, if you don't specify the filename, then the command will search
recursively.

When you enter only the command name, you will be prompted to enter the search
pattern and the files in which to search for the pattern. By default, the
Expand Down

0 comments on commit a7a290b

Please sign in to comment.