diff --git a/README.md b/README.md index c7151a1..6388fe1 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,25 @@ Fork of implementing the following additional features: 1) Implements key mappings in Grep output window. -2) Merges . -3) Escapes filenames, excluding \*\*, \*, and [?~]. +2) Directly pass command lines to shell unchanged. + +This fixes the following upstream issues: + + + + +Removes find and xargs dependencies. + +Removes the following features/options: +Prompting for \ if not specified +Prompting for \ if not specified +Grep\_Find\_Path +Grep\_Xargs\_Path +Grep\_Default\_Filelist +Grep\_Find\_Use\_Xargs +Grep\_Xargs\_Options +Grep\_Cygwin\_Find +Grep\_Shell\_Escape\_Char Plugin to integrate various grep like search tools with Vim. diff --git a/autoload/grep.vim b/autoload/grep.vim index 6f9c042..42069a5 100644 --- a/autoload/grep.vim +++ b/autoload/grep.vim @@ -1,7 +1,7 @@ " File: grep.vim " Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com), Lucía Andrea Illanes Albornoz (lucia AT luciaillanes DOT de) -" Version: 3.1 -" Last Modified: March 5, 2023 +" Version: 3.11 +" Last Modified: March 6, 2023 " " Plugin to integrate grep like utilities with Vim " Supported utilities are: grep, fgrep, egrep, agrep, findstr, ag, ack, @@ -154,16 +154,6 @@ if !exists("Ucg_Options") let Ucg_Options = '' endif -" Location of the find utility -if !exists("Grep_Find_Path") - let Grep_Find_Path = 'find' -endif - -" Location of the xargs utility -if !exists("Grep_Xargs_Path") - let Grep_Xargs_Path = 'xargs' -endif - " Open the Grep output window. Set this variable to zero, to not open " the Grep output window by default. You can open it manually by using " the :cwindow command. @@ -171,27 +161,6 @@ if !exists("Grep_OpenQuickfixWindow") let Grep_OpenQuickfixWindow = 1 endif -" Default grep file list -if !exists("Grep_Default_Filelist") - let Grep_Default_Filelist = '*' -endif - -" Use the 'xargs' utility in combination with the 'find' utility. Set this -" to zero to not use the xargs utility. -if !exists("Grep_Find_Use_Xargs") - let Grep_Find_Use_Xargs = 1 -endif - -" The command-line arguments to supply to the xargs utility -if !exists('Grep_Xargs_Options') - let Grep_Xargs_Options = '-0' -endif - -" The find utility is from the cygwin package or some other find utility. -if !exists("Grep_Cygwin_Find") - let Grep_Cygwin_Find = 0 -endif - " NULL device name to supply to grep. We need this because, grep will not " print the name of the file, if only one filename is supplied. We need the " filename for Vim quickfix processing. @@ -203,15 +172,6 @@ if !exists("Grep_Null_Device") endif endif -" Character to use to escape special characters before passing to grep. -if !exists("Grep_Shell_Escape_Char") - if has('win32') - let Grep_Shell_Escape_Char = '' - else - let Grep_Shell_Escape_Char = '\' - endif -endif - " The list of directories to skip while searching for a pattern. Set this " variable to '', if you don't want to skip directories. if !exists("Grep_Skip_Dirs") @@ -249,25 +209,25 @@ let s:cmdTable = { \ 'grep' : { \ 'cmdpath' : g:Grep_Path, \ 'optprefix' : '-', - \ 'defopts' : '-s -n -f -', + \ 'defopts' : '-s -n', \ 'opts' : g:Grep_Options, - \ 'expropt' : '--', + \ 'expropt' : '', \ 'nulldev' : g:Grep_Null_Device \ }, \ 'fgrep' : { \ 'cmdpath' : g:Fgrep_Path, \ 'optprefix' : '-', - \ 'defopts' : '-s -n -f -', + \ 'defopts' : '-s -n', \ 'opts' : g:Fgrep_Options, - \ 'expropt' : '-e', + \ 'expropt' : '', \ 'nulldev' : g:Grep_Null_Device \ }, \ 'egrep' : { \ 'cmdpath' : g:Egrep_Path, \ 'optprefix' : '-', - \ 'defopts' : '-s -n -f -', + \ 'defopts' : '-s -n', \ 'opts' : g:Egrep_Options, - \ 'expropt' : '-e', + \ 'expropt' : '', \ 'nulldev' : g:Grep_Null_Device \ }, \ 'agrep' : { @@ -431,20 +391,20 @@ endfunc " runGrepCmdAsync() " Run the grep command asynchronously -func! s:runGrepCmdAsync(cmd_name, cmd, pattern, action) abort +func! s:runGrepCmdAsync(cmd_name, cmdline, action) abort if s:grep_cmd_job isnot 0 " If the job is already running for some other search, stop it. call job_stop(s:grep_cmd_job) caddexpr '[Search command interrupted]' endif - let title = '[Search results for ' . a:pattern . ']' + let title = '[Search results for ' . a:cmdline . ']' if a:action == 'add' caddexpr title . "\n" else cgetexpr title . "\n" endif - "caddexpr 'Search cmd: "' . a:cmd . '"' + "caddexpr 'Search cmd: "' . a:cmdline . '"' call setqflist([], 'a', {'title' : title}) " Save the quickfix list id, so that the grep output can be added to " the correct quickfix list @@ -456,9 +416,9 @@ func! s:runGrepCmdAsync(cmd_name, cmd, pattern, action) abort endif if has('win32') && !has('win32unix') && (&shell =~ 'cmd.exe') - let cmd_list = [a:cmd] + let cmd_list = [a:cmdline] else - let cmd_list = [&shell, &shellcmdflag, a:cmd] + let cmd_list = [&shell, &shellcmdflag, a:cmdline] endif let s:grep_cmd_job = job_start(cmd_list, \ {'callback' : function('grep#cmd_output_cb', [qf_id]), @@ -473,12 +433,6 @@ func! s:runGrepCmdAsync(cmd_name, cmd, pattern, action) abort return endif - if has_key({'Grep': 0, 'Egrep': 0, 'Fgrep': 0}, a:cmd_name) - let channel = job_getchannel(s:grep_cmd_job) - call ch_sendraw(channel, a:pattern) - call ch_close_in(channel) - endif - " Open the grep output window if g:Grep_OpenQuickfixWindow == 1 " Open the quickfix window below the current window @@ -527,8 +481,10 @@ func! s:openInWindow(closefl, currentfl, verticalfl) abort endfunc " runGrepCmd() -" Run the specified grep command using the supplied pattern -func! s:runGrepCmd(cmd_name, cmd, pattern, action) abort +" Run the specified grep command line w/ system() +func! s:runGrepCmd(cmd_name, cmd, cmd_args, action) abort + let cmdline = s:formFullCmd(a:cmd, a:cmd_args) + if has('win32') && !has('win32unix') && (&shell =~ 'cmd.exe') " Windows does not correctly deal with commands that have more than 1 " set of double quotes. It will strip them all resulting in: @@ -537,10 +493,10 @@ func! s:runGrepCmd(cmd_name, cmd, pattern, action) abort " command inside a batch file and call the batch file. " Do this only on Win2K, WinXP and above. let s:grep_tempfile = fnamemodify(tempname(), ':h:8') . '\mygrep.cmd' - call writefile(['@echo off', a:cmd], s:grep_tempfile) + call writefile(['@echo off', cmdline], s:grep_tempfile) if g:Grep_Run_Async - call s:runGrepCmdAsync(a:cmd_name, s:grep_tempfile, a:pattern, a:action) + call s:runGrepCmdAsync(a:cmd_name, s:grep_tempfile, a:action) return endif let cmd_output = system('"' . s:grep_tempfile . '"') @@ -551,9 +507,9 @@ func! s:runGrepCmd(cmd_name, cmd, pattern, action) abort endif else if g:Grep_Run_Async - return s:runGrepCmdAsync(a:cmd_name, a:cmd, a:pattern, a:action) + return s:runGrepCmdAsync(a:cmd_name, cmdline, a:action) endif - let cmd_output = system(a:cmd) + let cmd_output = system(cmdline) endif " Do not check for the shell_error (return code from the command). @@ -561,7 +517,7 @@ func! s:runGrepCmd(cmd_name, cmd, pattern, action) abort " are problems with a few input files. if cmd_output == '' - call s:warnMsg('Error: Pattern ' . a:pattern . ' not found') + call s:warnMsg('Error: No search results') return endif @@ -571,7 +527,7 @@ func! s:runGrepCmd(cmd_name, cmd, pattern, action) abort set verbose&vim exe 'redir! > ' . tmpfile - silent echon '[Search results for pattern: ' . a:pattern . "]\n" + silent echon '[Search results for ' . a:cmd . "]\n" silent echon cmd_output redir END @@ -597,55 +553,10 @@ func! s:runGrepCmd(cmd_name, cmd, pattern, action) abort call delete(tmpfile) endfunc -" parseArgs() -" Parse arguments to the grep command. The expected order for the various -" arguments is: -" -" grep command-line flags are specified using the "-flag" format. -" the next argument is assumed to be the pattern. -" and the next arguments are assumed to be filenames or file patterns. -func! s:parseArgs(cmd_name, args) abort - let cmdopt = '' - let pattern = '' - let filepattern = '' - - let optprefix = s:cmdTable[a:cmd_name].optprefix - - for one_arg in a:args - if one_arg[0] == optprefix && pattern == '' - " Process grep arguments at the beginning of the argument list - let cmdopt = cmdopt . ' ' . one_arg - elseif pattern == '' - " Only one search pattern can be specified - let pattern = one_arg - else - " More than one file patterns can be specified - if filepattern != '' - let filepattern = filepattern . ' ' . one_arg - else - let filepattern = one_arg - endif - endif - endfor - - return [cmdopt, pattern, filepattern] -endfunc - -" recursive_search_cmd -" Returns TRUE if a command recursively searches by default. -func! s:recursive_search_cmd(cmd_name) abort - return a:cmd_name == 'ag' || - \ a:cmd_name == 'rg' || - \ a:cmd_name == 'ack' || - \ a:cmd_name == 'git' || - \ a:cmd_name == 'pt' || - \ a:cmd_name == 'ucg' -endfunc - " formFullCmd() " Generate the full command to run based on the user supplied command name, -" options, pattern and file names. -func! s:formFullCmd(cmd_name, useropts, pattern, filenames) abort +" command line, and default options. +func! s:formFullCmd(cmd_name, args) abort if !has_key(s:cmdTable, a:cmd_name) call s:warnMsg('Error: Unsupported command ' . a:cmd_name) return '' @@ -662,29 +573,17 @@ func! s:formFullCmd(cmd_name, useropts, pattern, filenames) abort if s:cmdTable[a:cmd_name].opts != '' let cmdopt = cmdopt . ' ' . s:cmdTable[a:cmd_name].opts endif - if a:useropts != '' - let cmdopt = cmdopt . ' ' . a:useropts - endif if s:cmdTable[a:cmd_name].expropt != '' let cmdopt = cmdopt . ' ' . s:cmdTable[a:cmd_name].expropt endif if has_key({'grep': 0, 'egrep': 0, 'fgrep': 0}, a:cmd_name) let fullcmd = s:cmdTable[a:cmd_name].cmdpath . ' ' . - \ cmdopt + \ cmdopt . ' ' . + \ a:args else let fullcmd = s:cmdTable[a:cmd_name].cmdpath . ' ' . - \ cmdopt . ' ' . - \ a:pattern - endif - - if a:filenames != '' - let filenames = shellescape(a:filenames) - let filenames = substitute(filenames, '\(\\\)\@ 0 && (a:1 == '-?' || a:1 == '-h') - echo 'Usage: ' . a:cmd_name . ' [] [ ' . - \ '[]]' - return - endif - - " Parse the arguments and get the grep options, search pattern - " and list of file names/patterns - let [opts, pattern, filenames] = s:parseArgs(a:grep_cmd, a:000) - - " No argument supplied. Get the identifier and file list from user - if pattern == '' - let pattern = input('Search for pattern: ', expand('')) - if pattern == '' - return - endif - echo "\r" - endif - - let cwd = getcwd() - if g:Grep_Cygwin_Find == 1 - let cwd = substitute(cwd, "\\", "/", 'g') - endif - let startdir = input('Start searching from directory: ', cwd, 'dir') - if startdir == '' - return - endif - echo "\r" - - if !isdirectory(startdir) - call s:warnMsg('Error: Directory ' . startdir . " doesn't exist") - return - endif - - " To compare against the current directory, convert to full path - let startdir = fnamemodify(startdir, ':p:h') - - if startdir == cwd - let startdir = '.' - else - " On MS-Windows, convert the directory name to 8.3 style pathname. - " Otherwise, using a path with space characters causes problems. - if has('win32') - let startdir = fnamemodify(startdir, ':8') - endif - endif - - if filenames == '' - let filenames = input('Search in files matching pattern: ', - \ g:Grep_Default_Filelist) - if filenames == '' - return - endif - echo "\r" - endif - - let find_file_pattern = '' - for one_pattern in split(filenames, ' ') - if find_file_pattern != '' - let find_file_pattern = find_file_pattern . ' -o' - endif - let find_file_pattern = find_file_pattern . ' -name ' . - \ shellescape(one_pattern) - endfor - let find_file_pattern = g:Grep_Shell_Escape_Char . '(' . - \ find_file_pattern . ' ' . g:Grep_Shell_Escape_Char . ')' + let grep_cmd = a:grep_cmd - let find_prune = '' if g:Grep_Skip_Dirs != '' for one_dir in split(g:Grep_Skip_Dirs, ' ') - if find_prune != '' - let find_prune = find_prune . ' -o' - endif - let find_prune = find_prune . ' -name ' . - \ shellescape(one_dir) + let grep_cmd = "--exclude-dir=" . shellescape(one_dir) . " " . grep_cmd endfor - - let find_prune = '-type d ' . g:Grep_Shell_Escape_Char . '(' . - \ find_prune . ' ' . g:Grep_Shell_Escape_Char . ')' . - \ ' -prune -o' - endif - - let find_skip_files = '-type f' - for one_file in split(g:Grep_Skip_Files, ' ') - let find_skip_files = find_skip_files . ' ! -name ' . - \ shellescape(one_file) - endfor - - " On MS-Windows, convert the find/xargs program path to 8.3 style path - if has('win32') - let g:Grep_Find_Path = fnamemodify(g:Grep_Find_Path, ':8') - let g:Grep_Xargs_Path = fnamemodify(g:Grep_Xargs_Path, ':8') endif - if g:Grep_Find_Use_Xargs == 1 - let grep_cmd = s:formFullCmd(a:grep_cmd, opts, pattern, '') - let cmd = g:Grep_Find_Path . ' "' . startdir . '"' - \ . ' ' . find_prune - \ . ' ' . find_skip_files - \ . ' ' . find_file_pattern - \ . " -print0 | " - \ . g:Grep_Xargs_Path . ' ' . g:Grep_Xargs_Options - \ . ' ' . grep_cmd - else - let grep_cmd = s:formFullCmd(a:grep_cmd, opts, pattern, '{}') - let cmd = g:Grep_Find_Path . ' ' . startdir - \ . ' ' . find_prune . " -prune -o" - \ . ' ' . find_skip_files - \ . ' ' . find_file_pattern - \ . " -exec " . grep_cmd . ' ' . - \ g:Grep_Shell_Escape_Char . ';' + if g:Grep_Skip_Files != '' + for one_file in split(g:Grep_Skip_Files, ' ') + let grep_cmd = "--exclude=" . shellescape(one_file) . " " . grep_cmd + endfor endif - call s:runGrepCmd(a:cmd_name, cmd, pattern, a:action) + call s:runGrepCmd(a:cmd_name, grep_cmd, a:000[0], a:action) endfunc " grep#runGrepSpecial() -" Search for a pattern in all the opened buffers or filenames in the -" argument list +" Search in all the opened buffers or filenames in the argument list func! grep#runGrepSpecial(cmd_name, which, action, ...) abort - if a:0 > 0 && (a:1 == '-?' || a:1 == '-h') - echo 'Usage: ' . a:cmd_name . ' [] []' - return - endif + let grep_args = a:000[0] " Search in all the Vim buffers if a:which == 'buffer' @@ -867,6 +663,7 @@ func! grep#runGrepSpecial(cmd_name, which, action, ...) abort call s:warnMsg('Error: Buffer list is empty') return endif + let grep_args = grep_args . ' ' . filenames elseif a:which == 'args' " Search in all the filenames in the argument list let filenames = s:getListOfArgFiles() @@ -875,6 +672,7 @@ func! grep#runGrepSpecial(cmd_name, which, action, ...) abort call s:warnMsg('Error: Argument list is empty') return endif + let grep_args = grep_args . ' ' . filenames endif if has('win32') && !has('win32unix') @@ -885,58 +683,13 @@ func! grep#runGrepSpecial(cmd_name, which, action, ...) abort let grep_cmd = 'grep' endif - " Parse the arguments and get the command line options and pattern. - " Filenames are not be supplied and should be ignored. - let [opts, pattern, temp] = s:parseArgs(grep_cmd, a:000) - - if pattern == '' - " No argument supplied. Get the identifier and file list from user - let pattern = input('Search for pattern: ', expand('')) - if pattern == '' - return - endif - echo "\r" - endif - - " Form the complete command line and run it - let cmd = s:formFullCmd(grep_cmd, opts, pattern, filenames) - call s:runGrepCmd(a:cmd_name, cmd, pattern, a:action) + call s:runGrepCmd(a:cmd_name, grep_cmd, grep_args, a:action) endfunc " grep#runGrep() " Run the specified grep command func! grep#runGrep(cmd_name, grep_cmd, action, ...) abort - if a:0 > 0 && (a:1 == '-?' || a:1 == '-h') - echo 'Usage: ' . a:cmd_name . ' [] [ ' . - \ '[]]' - return - endif - - " Parse the arguments and get the grep options, search pattern - " and list of file names/patterns - let [opts, pattern, filenames] = s:parseArgs(a:grep_cmd, a:000) - - " Get the identifier and file list from user - if pattern == '' - let pattern = input('Search for pattern: ', expand('')) - if pattern == '' - return - endif - echo "\r" - endif - - if filenames == '' && !s:recursive_search_cmd(a:grep_cmd) - let filenames = input('Search in files: ', g:Grep_Default_Filelist, - \ 'file') - if filenames == '' - return - endif - echo "\r" - endif - - " Form the complete command line and run it - let cmd = s:formFullCmd(a:grep_cmd, opts, pattern, filenames) - call s:runGrepCmd(a:cmd_name, cmd, pattern, a:action) + call s:runGrepCmd(a:cmd_name, a:grep_cmd, a:000[0], a:action) endfunc " restore 'cpo' diff --git a/doc/greppie.txt b/doc/greppie.txt index de91643..a61e8ae 100644 --- a/doc/greppie.txt +++ b/doc/greppie.txt @@ -2,7 +2,7 @@ Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com), Lucía Andrea Illanes Albornoz (lucia AT luciaillanes DOT de) For Vim version 7.0 and above -Last change: March 5, 2023 +Last change: March 6, 2023 ============================================================================== *vim-greppie-license* @@ -51,13 +51,11 @@ features, but you can still use the rest of the features supported by the plugin. 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 Linux/Unix and -MacOS installations. For MS-Windows systems, you can download the GNU grep -and find utilities from the following sites: +utilities. These tools are present in most of the Linux/Unix and MacOS +installations. For MS-Windows systems, you can download the GNU grep +utility from the following site: http://gnuwin32.sourceforge.net/packages/grep.htm - http://gnuwin32.sourceforge.net/packages/findutils.htm On MS-Windows, you can use the findstr utility to search for patterns. This is available by default on all MS-Windows systems. @@ -97,11 +95,7 @@ download the universal code grep utility from: https://gvansickle.github.io/ucg -The silver searcher, ripgrep, ack, sift, platinum searcher and universal code -grep utilities can search for a pattern recursively across directories without -using any other additional utilities like find and xargs. - -The github repository for this plugin is at https://github.com/yegappan/grep +The github repository for this plugin is at https://github.com/lalbornoz/vim-greppie ============================================================================== *vim-greppie-installation* @@ -173,47 +167,47 @@ The vim-greppie.vim plugin introduces the following Vim commands: The above commands can be invoked like this: - :Grep [] [ []] - :Rgrep [] [ []] - :Fgrep [] [ []] - :Rfgrep [] [ []] - :Egrep [] [ []] - :Regrep [] [ []] - :Agrep [] [ []] - :Ragrep [] [ []] - :Findstr [] [ []] - :Ag [] [ []] - :Ack [] [ []] - :Rg [] [ []] - :Gitgrep [] [ []] - :Sift [] [ []] - :Ptgrep [] [ []] - :Ucgrep [] [ []] - - :GrepAdd [] [ []] - :RgrepAdd [] [ []] - :FgrepAdd [] [ []] - :RfgrepAdd [] [ []] - :EgrepAdd [] [ []] - :RegrepAdd [] [ []] - :FindstrAdd [] [ []] - :AgrepAdd [] [ []] - :RagrepAdd [] [ []] - :AgAdd [] [ []] - :AckAdd [] [ []] - :RgAdd [] [ []] - :GitgrepAdd [] [ []] - :SiftAdd [] [ []] - :PtgrepAdd [] [ []] - :UcgrepAdd [] [ []] - - :GrepBuffer [] [] - :Bgrep [] [] - :GrepArgs [] [] - - :GrepBufferAdd [] [] - :BgrepAdd [] [] - :GrepArgsAdd [] [] + :Grep [] + :Rgrep [] + :Fgrep [] + :Rfgrep [] + :Egrep [] + :Regrep [] + :Agrep [] + :Ragrep [] + :Findstr [] + :Ag [] + :Ack [] + :Rg [] + :Gitgrep [] + :Sift [] + :Ptgrep [] + :Ucgrep [] + + :GrepAdd [] + :RgrepAdd [] + :FgrepAdd [] + :RfgrepAdd [] + :EgrepAdd [] + :RegrepAdd [] + :FindstrAdd [] + :AgrepAdd [] + :RagrepAdd [] + :AgAdd [] + :AckAdd [] + :RgAdd [] + :GitgrepAdd [] + :SiftAdd [] + :PtgrepAdd [] + :UcgrepAdd [] + + :GrepBuffer [] + :Bgrep [] + :GrepArgs [] + + :GrepBufferAdd [] + :BgrepAdd [] + :GrepArgsAdd [] In the above commands, all the arguments are optional. @@ -222,35 +216,17 @@ to the above commands. To always pass a set of command line flags to the grep command, you can set the Grep_Options variable. There are similar variables for other commands. -You can specify the grep pattern to search as an argument to the above -commands. If the is not specified, then you will be prompted -to enter a search pattern. By default, the keyword under the cursor is -displayed for the search pattern prompt. You can accept the default or modify -it. - -The search pattern is automatically enclosed by the escape character. You -should not enclose the search pattern with a shell escape character. - -If you want to specify a search pattern with space characters or a multi-word -pattern, then you should run the Grep command without any arguments and use -the search pattern input prompt to supply the search pattern. +You can specify the grep pattern to search and one or more file names (or file +patterns) as an argument to the above commands. -You can specify one or more file names (or file patterns) to the above -commands. If the 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. +Grep patterns as well as file names are passed through unchanged to the shell +as part of the command line. Thus, quote and escape as necessary and as you +ordinarily would on a shell prompt. When using search utilities like ag, ack, ripgrep and git grep which searches recursively by default, if you don't specify a 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 -keyword under the cursor is displayed for the search pattern prompt. -Depending on the command, you may prompted for additional parameters like the -directories to search for the pattern. - On MS-Windows, the command line options for the findstr.exe utility are prefixed with '/'. The ':Findstr' command accepts options prefixed with '/'. Examples: @@ -395,29 +371,6 @@ using the let command: :let Ucg_Path = '/usr/local/bin/ucg' -The 'Grep_Find_Path' variable is used to locate the find utility. By default, -this is set to 'find'. Note that on MS-Windows, there is a find.exe that is -part of the base OS. This find utility is different from the Unix find -utility. You cannot use this utility with this plugin. You must install the -Unix compatible find utility and set the Grep_Find_Path variable to point to -the location of the utility. You can change this using the let command: - - :let Grep_Find_Path = 'C:\Progra~1\Grep\find.exe' - -The 'Grep_Xargs_Path' variable is used to locate the xargs utility. By -default, this is set to xargs. You can change this using the let command: - - :let Grep_Xargs_Path = 'C:\Progra~1\Grep\xargs.exe' - -When running any one of the Grep commands, you will be prompted for the files -in which to search for the pattern. The 'Grep_Default_Filelist' variable is -used to specify to default for this prompt. By default, this variable is set -to '*'. You can specify multiple matching patterns separated by spaces. You -can change this settings using the let command: - - :let Grep_Default_Filelist = '*.[chS]' - :let Grep_Default_Filelist = '*.c *.cpp *.asm' - The 'Grep_Options' variable is used to pass command line options to the grep command. By default, this is set to an empty string. You can change this using the let command: @@ -451,28 +404,6 @@ setting the 'Grep_OpenQuickfixWindow' variable to zero: You can manually open the quickfix window using the :cwindow command. -By default, for recursive searches, the 'find' and 'xargs' utilities are used. -If you don't have the 'xargs' utility or don't want to use the 'xargs' -utility, " then you can set the 'Grep_Find_Use_Xargs' variable to zero. If -this is set to zero, then only the 'find' utility is used for recursive -searches: - - :let Grep_Find_Use_Xargs = 0 - -To handle file names with space characters in them, the xargs utility is -invoked with the '-0' argument. If the xargs utility in your system doesn't -accept the '-0' argument, then you can change the Grep_Xargs_Options variable. -For example, to use the '--null' xargs argument, you can use the following -command: - - :let Grep_Xargs_Options = '--null' - -The Grep_Cygwin_Find variable should be set to 1, if you are using the find -utility from the cygwin package. This setting is used to handle the difference -between the backslash and forward slash path separators. - - :let Grep_Cygwin_Find = 1 - The 'Grep_Null_Device' variable specifies the name of the null device to pass to the grep commands. This is needed to force the grep commands to print the name of the file in which a match is found, if only one filename is specified. @@ -481,13 +412,6 @@ set to NUL. You can modify this by using the let command: :let Grep_Null_Device = '/dev/null' -The 'Grep_Shell_Escape_Char' variable specifies the escape character to use -for protecting special characters from being interpreted by the shell. For -Unix systems, this is set to '\' and for MS-Window systems, this is set to an -empty string. You can change this using the let command: - - :let Grep_Shell_Escape_Char = "'" - The 'Grep_Run_Async' variable specifies whether the grep commands are run synchronously or asynchronously. Depending on the Vim version, this variable is set automatically. If you want to force Vim to run the grep commands diff --git a/plugin/grep.vim b/plugin/grep.vim index b0749ff..7f54250 100644 --- a/plugin/grep.vim +++ b/plugin/grep.vim @@ -1,7 +1,7 @@ " File: grep.vim " Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com), Lucía Andrea Illanes Albornoz (lucia AT luciaillanes DOT de) -" Version: 3.1 -" Last Modified: March 5, 2023 +" Version: 3.11 +" Last Modified: March 6, 2023 " " Plugin to integrate grep like utilities with Vim " Supported utilities are: grep, fgrep, egrep, agrep, findstr, ag, ack, @@ -47,110 +47,110 @@ set cpo&vim " grep commands command! -nargs=* -complete=file Grep - \ call grep#runGrep('Grep', 'grep', 'set', ) + \ call grep#runGrep('Grep', 'grep', 'set', ) command! -nargs=* -complete=file Rgrep - \ call grep#runGrepRecursive('Rgrep', 'grep', 'set', ) + \ call grep#runGrepRecursive('Rgrep', 'grep', 'set', ) command! -nargs=* -complete=file GrepAdd - \ call grep#runGrep('GrepAdd', 'grep', 'add', ) + \ call grep#runGrep('GrepAdd', 'grep', 'add', ) command! -nargs=* -complete=file RgrepAdd - \ call grep#runGrepRecursive('RgrepAdd', 'grep', 'add', ) + \ call grep#runGrepRecursive('RgrepAdd', 'grep', 'add', ) " fgrep commands command! -nargs=* -complete=file Fgrep - \ call grep#runGrep('Fgrep', 'fgrep', 'set', ) + \ call grep#runGrep('Fgrep', 'fgrep', 'set', ) command! -nargs=* -complete=file Rfgrep - \ call grep#runGrepRecursive('Rfgrep', 'fgrep', 'set', ) + \ call grep#runGrepRecursive('Rfgrep', 'fgrep', 'set', ) command! -nargs=* -complete=file FgrepAdd - \ call grep#runGrep('FgrepAdd', 'fgrep', 'add', ) + \ call grep#runGrep('FgrepAdd', 'fgrep', 'add', ) command! -nargs=* -complete=file RfgrepAdd - \ call grep#runGrepRecursive('RfgrepAdd', 'fgrep', 'add', ) + \ call grep#runGrepRecursive('RfgrepAdd', 'fgrep', 'add', ) " egrep commands command! -nargs=* -complete=file Egrep - \ call grep#runGrep('Egrep', 'egrep', 'set', ) + \ call grep#runGrep('Egrep', 'egrep', 'set', ) command! -nargs=* -complete=file Regrep - \ call grep#runGrepRecursive('Regrep', 'egrep', 'set', ) + \ call grep#runGrepRecursive('Regrep', 'egrep', 'set', ) command! -nargs=* -complete=file EgrepAdd - \ call grep#runGrep('EgrepAdd', 'egrep', 'add', ) + \ call grep#runGrep('EgrepAdd', 'egrep', 'add', ) command! -nargs=* -complete=file RegrepAdd - \ call grep#runGrepRecursive('RegrepAdd', 'egrep', 'add', ) + \ call grep#runGrepRecursive('RegrepAdd', 'egrep', 'add', ) " agrep commands command! -nargs=* -complete=file Agrep - \ call grep#runGrep('Agrep', 'agrep', 'set', ) + \ call grep#runGrep('Agrep', 'agrep', 'set', ) command! -nargs=* -complete=file Ragrep - \ call grep#runGrepRecursive('Ragrep', 'agrep', 'set', ) + \ call grep#runGrepRecursive('Ragrep', 'agrep', 'set', ) command! -nargs=* -complete=file AgrepAdd - \ call grep#runGrep('AgrepAdd', 'agrep', 'add', ) + \ call grep#runGrep('AgrepAdd', 'agrep', 'add', ) command! -nargs=* -complete=file RagrepAdd - \ call grep#runGrepRecursive('RagrepAdd', 'agrep', 'add', ) + \ call grep#runGrepRecursive('RagrepAdd', 'agrep', 'add', ) " Silver Searcher (ag) commands command! -nargs=* -complete=file Ag - \ call grep#runGrep('Ag', 'ag', 'set', ) + \ call grep#runGrep('Ag', 'ag', 'set', ) command! -nargs=* -complete=file AgAdd - \ call grep#runGrep('AgAdd', 'ag', 'add', ) + \ call grep#runGrep('AgAdd', 'ag', 'add', ) " Ripgrep (rg) commands command! -nargs=* -complete=file Rg - \ call grep#runGrep('Rg', 'rg', 'set', ) + \ call grep#runGrep('Rg', 'rg', 'set', ) command! -nargs=* -complete=file RgAdd - \ call grep#runGrep('RgAdd', 'rg', 'add', ) + \ call grep#runGrep('RgAdd', 'rg', 'add', ) " ack commands command! -nargs=* -complete=file Ack - \ call grep#runGrep('Ack', 'ack', 'set', ) + \ call grep#runGrep('Ack', 'ack', 'set', ) command! -nargs=* -complete=file AckAdd - \ call grep#runGrep('AckAdd', 'ack', 'add', ) + \ call grep#runGrep('AckAdd', 'ack', 'add', ) " git grep commands command! -nargs=* -complete=file Gitgrep - \ call grep#runGrep('Gitgrep', 'git', 'set', ) + \ call grep#runGrep('Gitgrep', 'git', 'set', ) command! -nargs=* -complete=file GitgrepAdd - \ call grep#runGrep('GitgrepAdd', 'git', 'add', ) + \ call grep#runGrep('GitgrepAdd', 'git', 'add', ) " sift commands command! -nargs=* -complete=file Sift - \ call grep#runGrep('Sift', 'sift', 'set', ) + \ call grep#runGrep('Sift', 'sift', 'set', ) command! -nargs=* -complete=file SiftAdd - \ call grep#runGrep('SiftAdd', 'sift', 'add', ) + \ call grep#runGrep('SiftAdd', 'sift', 'add', ) " Platinum Searcher commands command! -nargs=* -complete=file Ptgrep - \ call grep#runGrep('Ptgrep', 'pt', 'set', ) + \ call grep#runGrep('Ptgrep', 'pt', 'set', ) command! -nargs=* -complete=file PtgrepAdd - \ call grep#runGrep('PtgrepAdd', 'pt', 'add', ) + \ call grep#runGrep('PtgrepAdd', 'pt', 'add', ) " Universal Code Grep commands command! -nargs=* -complete=file Ucgrep - \ call grep#runGrep('Ucgrep', 'ucg', 'set', ) + \ call grep#runGrep('Ucgrep', 'ucg', 'set', ) command! -nargs=* -complete=file UcgrepAdd - \ call grep#runGrep('UcgrepAdd', 'ucg', 'add', ) + \ call grep#runGrep('UcgrepAdd', 'ucg', 'add', ) " findstr commands if has('win32') command! -nargs=* -complete=file Findstr - \ call grep#runGrep('Findstr', 'findstr', 'set', ) + \ call grep#runGrep('Findstr', 'findstr', 'set', ) command! -nargs=* -complete=file FindstrAdd - \ call grep#runGrep('FindstrAdd', 'findstr', 'add', ) + \ call grep#runGrep('FindstrAdd', 'findstr', 'add', ) endif " Buffer list grep commands command! -nargs=* GrepBuffer - \ call grep#runGrepSpecial('GrepBuffer', 'buffer', 'set', ) + \ call grep#runGrepSpecial('GrepBuffer', 'buffer', 'set', ) command! -nargs=* Bgrep - \ call grep#runGrepSpecial('Bgrep', 'buffer', 'set', ) + \ call grep#runGrepSpecial('Bgrep', 'buffer', 'set', ) command! -nargs=* GrepBufferAdd - \ call grep#runGrepSpecial('GrepBufferAdd', 'buffer', 'add', ) + \ call grep#runGrepSpecial('GrepBufferAdd', 'buffer', 'add', ) command! -nargs=* BgrepAdd - \ call grep#runGrepSpecial('BgrepAdd', 'buffer', 'add', ) + \ call grep#runGrepSpecial('BgrepAdd', 'buffer', 'add', ) " Argument list grep commands command! -nargs=* GrepArgs - \ call grep#runGrepSpecial('GrepArgs', 'args', 'set', ) + \ call grep#runGrepSpecial('GrepArgs', 'args', 'set', ) command! -nargs=* GrepArgsAdd - \ call grep#runGrepSpecial('GrepArgsAdd', 'args', 'add', ) + \ call grep#runGrepSpecial('GrepArgsAdd', 'args', 'add', ) " Add the Tools->Search Files menu if has('gui_running')