Skip to content

Commit 3624911

Browse files
committed
Redir stdin to null only for ack, rg and ag commands
1 parent a7a290b commit 3624911

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

‎autoload/grep.vim‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,12 @@ function! s:parseArgs(args)
379379
return [cmdopt, pattern, filepattern]
380380
endfunction
381381

382+
" recursive_search_cmd
383+
" Returns TRUE if a command recursively searches by default.
384+
function! s:recursive_search_cmd(cmd_name)
385+
return a:cmd_name == 'ag' || a:cmd_name == 'rg' || a:cmd_name == 'ack'
386+
endfunction
387+
382388
" formFullCmd()
383389
" Generate the full command to run based on the user supplied command name,
384390
" options, pattern and file names.
@@ -455,8 +461,10 @@ function! s:formFullCmd(cmd_name, useropts, pattern, filenames)
455461

456462
" Some commands like ripgrep try to read from stdin. This hangs the
457463
" command as Vim controls stdin. To avoid this problem, redirect stdin to
458-
" the NULL device.
459-
let fullcmd = fullcmd . ' < ' . g:Grep_Null_Device
464+
" the NULL device for commands that search recursively by default.
465+
if s:recursive_search_cmd(a:cmd_name)
466+
let fullcmd = fullcmd . ' < ' . g:Grep_Null_Device
467+
endif
460468

461469
return fullcmd
462470
endfunction
@@ -648,12 +656,6 @@ function! grep#runGrepSpecial(cmd_name, which, action, ...)
648656
call s:runGrepCmd(cmd, pattern, a:action)
649657
endfunction
650658

651-
" recursive_search_cmd
652-
" Returns TRUE if a command recursively searches by default.
653-
function! s:recursive_search_cmd(cmd_name)
654-
return a:cmd_name == 'ag' || a:cmd_name == 'rg' || a:cmd_name == 'ack'
655-
endfunction
656-
657659
" grep#runGrep()
658660
" Run the specified grep command
659661
function! grep#runGrep(cmd_name, grep_cmd, action, ...)

0 commit comments

Comments
 (0)