add vim conf files
[arrow.git] / conf_slk120 / vim / _vim / plugin / grep.vim
blob87f881f74dc04c408a7b3c49626700aee9ad2630
1 " File: grep.vim
2 " Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
3 " Version: 1.6
4 " Last Modified: August 10, 2005
5
6 " Overview
7 " --------
8 " The grep.vim plugin script integrates the grep/fgrep/egrep/agrep tools with
9 " Vim. To use this script, you need the grep, fgrep, egrep, agrep, find and
10 " xargs utilities. These tools come with most of the Unix installations. For
11 " MS-Windows systems, you can download these tools from the
12 " http://unxutils.sourceforge.net or http://gnuwin32.sourceforge.net site.
14 " Usage
15 " -----
16 " The grep.vim plugin script introduces the following commands:
18 " :Grep        - Search for the specified pattern in the specified files
19 " :Rgrep       - Run recursive grep
20 " :GrepBuffer  - Search for a pattern on all open buffers
21 " :Bgrep       - Same as :GrepBuffer
22 " :GrepArgs    - Search for a pattern on all the Vim argument filenames (:args)
23 " :Fgrep       - Run fgrep
24 " :Rfgrep      - Run recursive fgrep
25 " :Egrep       - Run egrep
26 " :Regrep      - Run recursive egrep
27 " :Agrep       - Run agrep
28 " :Ragrep      - Run recursive agrep
30 " The above commands can be invoked like this:
32 "    :Grep   [<grep_options>] [<search_pattern> [<file_name(s)>]]
33 "    :Rgrep  [<grep_options>] [<search_pattern> [<file_name(s)>]]
34 "    :Fgrep  [<grep_options>] [<search_pattern> [<file_name(s)>]]
35 "    :Rfgrep [<grep_options>] [<search_pattern> [<file_name(s)>]]
36 "    :Egrep  [<grep_options>] [<search_pattern> [<file_name(s)>]]
37 "    :Regrep [<grep_options>] [<search_pattern> [<file_name(s)>]]
38 "    :Agrep  [<grep_options>] [<search_pattern> [<file_name(s)>]]
39 "    :Ragrep [<grep_options>] [<search_pattern> [<file_name(s)>]]
41 "    :GrepBuffer [<grep_options>] [<search_pattern>]
42 "    :Bgrep [<grep_options>] [<search_pattern>]
43 "    :GrepArgs [<grep_options>] [<search_pattern>]
45 " In the above commands, all the arguments are optional.
47 " You can specify grep options like -i (ignore case) or -w (search for a word)
48 " to the above commands.  If the <grep_options> are not specified, then the
49 " default grep options specified by the variable Grep_Default_Options will be
50 " used.
52 " You can specify the grep pattern to search as argument to the above
53 " commands.  If the <search_pattern> is not specified, then you will be
54 " prompted to enter a search pattern. By default, the keyword under the cursor
55 " will be displayed for the search pattern prompt. You can accept the default
56 " or modify it.
58 " The search pattern is automatically enclosed by the character specified in
59 " the Grep_Shell_Quote_Char variable. You should not enclose the search
60 " pattern with a shell escape character.
62 " If you want to specify a search pattern with space characters or a
63 " multi-word pattern, then you should use the Grep command input prompt to
64 " supply the pattern.
66 " You can specify one or more file names (or file patterns) to the above
67 " commands.  If the <file_names> are not specified, then you will be prompted
68 " to enter file names.  By default, the pattern specified by the
69 " Grep_Default_Filelist variable will be used. To specify the file name(s) as
70 " an argument to the above commands, you should specify the search pattern
71 " also.
73 " When you enter only the command name, you will be prompted to enter
74 " the search pattern and the files in which to search for the pattern. By
75 " default, the keyword under the cursor will be displayed for the search
76 " pattern prompt.  Depending on the command, you may prompted for additional
77 " parameters like the directories to search for the pattern.
79 " You can retrieve previously entered values for the Grep prompts using the up
80 " and down arrow keys. You can cancel the command by pressing the escape key.
81 " You can use CTRL-U to erase the default shown for the prompt and CTRL-W to
82 " erase the previous word in the prompt. For more information about editing
83 " the prompt, read :help cmdline-editing
85 " After invoking any of the grep commands, you can cancel the command, when
86 " you are prompted for a search pattern or file names or a directory by
87 " pressing the <Esc> key. You cannot cancel (or kill) the
88 " grep/fgrep/egrep/agrep commands after the external command is invoked.
90 " You can map a key to invoke any of the above commands. For example, the
91 " following map will invoke the :Grep command to search for the keyword under
92 " the cursor:
94 "       nnoremap <silent> <F3> :Grep<CR>
96 " The output of the grep command will be listed in the Vim quickfix window.
97 " 1. You can select a line in the quickfix window and press <Enter> or double
98 "    click on a match to jump to that line.
99 " 2. You can use the ":cnext" and ":cprev" commands to the jump to the next or
100 "    previous output line.
101 " 3. You can use the ":colder" and ":cnewer" commands to go between multiple
102 "    grep quickfix output windows.
103 " 4. The quickfix window need not be opened always to use the grep output.
104 "    You can close the quickfix window and use the quickfix commands to jump
105 "    to the grep matches.  Use the ":copen" command to open the quickfix
106 "    window again.
108 " For more information about other quickfix commands read ":help quickfix"
110 " Configuration
111 " -------------
112 " By changing the following variables you can configure the behavior of this
113 " script. Set the following variables in your .vimrc file using the 'let'
114 " command.
116 " The 'Grep_Path' variable is used to locate the grep utility. By default,
117 " this is set to grep. You can change this using the let command:
119 "       :let Grep_Path = 'd:\tools\grep.exe'
121 " The 'Fgrep_Path' variable is used to locate the fgrep utility. By default,
122 " this is set to fgrep. You can change this using the let command:
124 "       :let Fgrep_Path = 'd:\tools\fgrep.exe'
126 " The 'Egrep_Path' variable is used to locate the egrep utility. By default,
127 " this is set to egrep. You can change this using the let command:
129 "       :let Egrep_Path = 'd:\tools\egrep.exe'
131 " The 'Agrep_Path' variable is used to locate the agrep utility. By default,
132 " this is set to agrep. You can change this using the let command:
134 "       :let Agrep_Path = 'd:\tools\agrep.exe'
136 " The 'Grep_Find_Path' variable is used to locate the find utility. By
137 " default, this is set to d:\tools\find.exe. You can change this using the let
138 " command:
140 "       :let Grep_Find_Path = 'd:\tools\find.exe'
142 " The 'Grep_Xargs_Path' variable is used to locate the xargs utility. By
143 " default, this is set to xargs. You can change this using the let
144 " command:
146 "       :let Grep_Xargs_Path = 'd:\tools\xargs.exe'
148 " When running any one of the Grep commands, you will be prompted for the
149 " files in which to search for the pattern. The 'Grep_Default_Filelist'
150 " variable is used to specify to default for this prompt. By default, this
151 " variable is set to '*'. You can specify multiple matching patterns separated
152 " by spaces. You can change this settings using the let command:
154 "       :let Grep_Default_Filelist = '*.[chS]'
155 "       :let Grep_Default_Filelist = '*.c *.cpp *.asm'
157 " The 'Grep_Default_Options' is used to pass default command line options to
158 " the grep/fgrep/egrep/agrep utilities. By default, this is set to an empty
159 " string. You can change this using the let command:
161 "       :let Grep_Default_Options = '-i'
163 " The 'Grep_Skip_Dirs' variable specifies the list of directories to skip
164 " while doing recursive searches. By default, this is set to 'RCS CVS SCCS'.
165 " You can change this using the let command:
167 "       :let Grep_Skip_Dirs = 'dir1 dir2 dir3'
169 " The 'Grep_Skip_Files' variable specifies the list of files to skip while
170 " doing recursive searches. By default, this is set to '*~ *,v s.*'. You can
171 " change this using the let command:
173 "       :let Grep_Skip_Files = '*.bak *~'
175 " By default, when you invoke the Grep commands the quickfix window will be
176 " opened with the grep output.  You can disable opening the quickfix window,
177 " by setting the 'Grep_OpenQuickfixWindow' variable  to zero:
179 "       :let Grep_OpenQuickfixWindow = 0
181 " You can manually open the quickfix window using the :cwindow command.
183 " By default, for recursive searches, the find with the xargs utility is used.
184 " If you don't have the xargs utility or don't want to use the xargs utility,
185 " then you can set the 'Grep_Find_Use_Xargs' variable to zero. If this is set
186 " to zero, then only the find utility will be used to do recursive searches:
188 "       :let Grep_Find_Use_Xargs = 0
190 " The Grep_Cygwin_Find variable should be set to 1, if you are using the find
191 " utility from the cygwin package. This setting is used to handle the
192 " difference between the backslash and forward slash path separators.
194 "       :let Grep_Cygwin_Find = 1
196 " The 'Grep_Null_Device' variable specifies the name of the null device to
197 " pass to the grep commands. This is needed to force the grep commands to
198 " print the name of the file in which a match is found, if only one filename
199 " is specified. For Unix systems, this is set to /dev/null and for MS-Windows
200 " systems, this is set to NUL. You can modify this by using the let command:
202 "       :let Grep_Null_Device = '/dev/null'
204 " The 'Grep_Shell_Quote_Char' variable specifies the quote character to use
205 " for protecting patterns from being interpreted by the shell. For Unix
206 " systems, this is set to "'" and for MS-Window systems, this is set to an
207 " empty string.  You can change this using the let command:
209 "       :let Grep_Shell_Quote_Char = "'"
211 " The 'Grep_Shell_Escape_Char' variable specifies the escape character to use
212 " for protecting special characters from being interpreted by the shell.  For
213 " Unix systems, this is set to '\' and for MS-Window systems, this is set to
214 " an empty string.  You can change this using the let command:
216 "       :let Grep_Shell_Escape_Char = "'"
218 " --------------------- Do not modify after this line ---------------------
219 if exists("loaded_grep")
220     finish
221 endif
222 let loaded_grep = 1
224 " Line continuation used here
225 let s:cpo_save = &cpo
226 set cpo&vim
228 " Location of the grep utility
229 if !exists("Grep_Path")
230     let Grep_Path = 'grep'
231 endif
233 " Location of the fgrep utility
234 if !exists("Fgrep_Path")
235     let Fgrep_Path = 'fgrep'
236 endif
238 " Location of the egrep utility
239 if !exists("Egrep_Path")
240     let Egrep_Path = 'egrep'
241 endif
243 " Location of the agrep utility
244 if !exists("Agrep_Path")
245     let Agrep_Path = 'agrep'
246 endif
248 " Location of the find utility
249 if !exists("Grep_Find_Path")
250     let Grep_Find_Path = 'find'
251 endif
253 " Location of the xargs utility
254 if !exists("Grep_Xargs_Path")
255     let Grep_Xargs_Path = 'xargs'
256 endif
258 " Open the Grep output window.  Set this variable to zero, to not open
259 " the Grep output window by default.  You can open it manually by using
260 " the :cwindow command.
261 if !exists("Grep_OpenQuickfixWindow")
262     let Grep_OpenQuickfixWindow = 1
263 endif
265 " Default grep file list
266 if !exists("Grep_Default_Filelist")
267     let Grep_Default_Filelist = '*'
268 endif
270 " Default grep options
271 if !exists("Grep_Default_Options")
272     let Grep_Default_Options = ''
273 endif
275 " Use the 'xargs' utility in combination with the 'find' utility. Set this
276 " to zero to not use the xargs utility.
277 if !exists("Grep_Find_Use_Xargs")
278     let Grep_Find_Use_Xargs = 1
279 endif
281 " The find utility is from the cygwin package or some other find utility.
282 if !exists("Grep_Cygwin_Find")
283     let Grep_Cygwin_Find = 0
284 endif
286 " NULL device name to supply to grep.  We need this because, grep will not
287 " print the name of the file, if only one filename is supplied. We need the
288 " filename for Vim quickfix processing.
289 if !exists("Grep_Null_Device")
290     if has("win32") || has("win16") || has("win95")
291         let Grep_Null_Device = 'NUL'
292     else
293         let Grep_Null_Device = '/dev/null'
294     endif
295 endif
297 " Character to use to quote patterns and filenames before passing to grep.
298 if !exists("Grep_Shell_Quote_Char")
299     if has("win32") || has("win16") || has("win95")
300         let Grep_Shell_Quote_Char = ''
301     else
302         let Grep_Shell_Quote_Char = "'"
303     endif
304 endif
306 " Character to use to escape special characters before passing to grep.
307 if !exists("Grep_Shell_Escape_Char")
308     if has("win32") || has("win16") || has("win95")
309         let Grep_Shell_Escape_Char = ''
310     else
311         let Grep_Shell_Escape_Char = '\'
312     endif
313 endif
315 " The list of directories to skip while searching for a pattern. Set this
316 " variable to '', if you don't want to skip directories.
317 if !exists("Grep_Skip_Dirs")
318     let Grep_Skip_Dirs = 'RCS CVS SCCS'
319 endif
321 " The list of files to skip while searching for a pattern. Set this variable
322 " to '', if you don't want to skip any files.
323 if !exists("Grep_Skip_Files")
324     let Grep_Skip_Files = '*~ *,v s.*'
325 endif
327 " RunGrepCmd()
328 " Run the specified grep command using the supplied pattern
329 function! s:RunGrepCmd(cmd, pattern)
330     let cmd_output = system(a:cmd)
332     if cmd_output == ""
333         echohl WarningMsg | 
334         \ echomsg "Error: Pattern " . a:pattern . " not found" | 
335         \ echohl None
336         return
337     endif
339     let tmpfile = tempname()
341     let old_verbose = &verbose
342     set verbose&vim
344     exe "redir! > " . tmpfile
345     silent echon '[Search results for pattern: ' . a:pattern . "]\n"
346     silent echon cmd_output
347     redir END
349     let &verbose = old_verbose
351     let old_efm = &efm
352     set efm=%f:%\\s%#%l:%m
354     if exists(":cgetfile")
355         execute "silent! cgetfile " . tmpfile
356     else
357         execute "silent! cfile " . tmpfile
358     endif
360     let &efm = old_efm
362     " Open the grep output window
363     if g:Grep_OpenQuickfixWindow == 1
364         " Open the quickfix window below the current window
365         botright copen
366     endif
368     call delete(tmpfile)
369 endfunction
371 " RunGrepRecursive()
372 " Run specified grep command recursively
373 function! s:RunGrepRecursive(cmd_name, grep_cmd, ...)
374     if a:0 > 0 && (a:1 == "-?" || a:1 == "-h")
375         echo a:cmd_name . " [<grep_options>] [<search_pattern> " .
376                         \ "[<file_name(s)>]]"
377         return
378     endif
380     let grep_opt    = ""
381     let pattern     = ""
382     let filepattern = ""
384     let argcnt= 1
385     while argcnt <= a:0
386         if a:{argcnt} =~ '^-'
387             let grep_opt = grep_opt . " " . a:{argcnt}
388         elseif pattern == ""
389             let pattern = g:Grep_Shell_Quote_Char . a:{argcnt} . 
390                             \ g:Grep_Shell_Quote_Char
391         else
392             let filepattern = filepattern . " " . a:{argcnt}
393         endif
394         let argcnt= argcnt + 1
395     endwhile
396     if grep_opt == ""
397         let grep_opt = g:Grep_Default_Options
398     endif
400     if a:grep_cmd == 'grep'
401         let grep_path = g:Grep_Path
402         let grep_expr_option = '--'
403     elseif a:grep_cmd == 'fgrep'
404         let grep_path = g:Fgrep_Path
405         let grep_expr_option = '-e'
406     elseif a:grep_cmd == 'egrep'
407         let grep_path = g:Egrep_Path
408         let grep_expr_option = '-e'
409     elseif a:grep_cmd == 'agrep'
410         let grep_path = g:Agrep_Path
411         let grep_expr_option = '-e'
412     else
413         return
414     endif
416     " No argument supplied. Get the identifier and file list from user
417     if pattern == "" 
418         let pattern = input("Search for pattern: ", expand("<cword>"))
419         if pattern == ""
420             return
421         endif
422         let pattern = g:Grep_Shell_Quote_Char . pattern . 
423                         \ g:Grep_Shell_Quote_Char
424     endif
426     let cwd = getcwd()
427     if g:Grep_Cygwin_Find == 1
428         let cwd = substitute(cwd, "\\", "/", "g")
429     endif
430     let startdir = input("Start searching from directory: ", cwd)
431     if startdir == ""
432         return
433     endif
435     if filepattern == ""
436         let filepattern = input("Search in files matching pattern: ", 
437                                           \ g:Grep_Default_Filelist)
438         if filepattern == ""
439             return
440         endif
441     endif
442     echo "\n"
444     let txt = filepattern . ' '
445     let find_file_pattern = ''
446     while txt != ''
447         let one_pattern = strpart(txt, 0, stridx(txt, ' '))
448         if find_file_pattern != ''
449             let find_file_pattern = find_file_pattern . ' -o'
450         endif
451         let find_file_pattern = find_file_pattern . ' -name ' .
452               \ g:Grep_Shell_Quote_Char . one_pattern . g:Grep_Shell_Quote_Char
453         let txt = strpart(txt, stridx(txt, ' ') + 1)
454     endwhile
455     let find_file_pattern = g:Grep_Shell_Escape_Char . '(' .
456                     \ find_file_pattern . ' ' . g:Grep_Shell_Escape_Char . ')'
458     let txt = g:Grep_Skip_Dirs
459     let find_prune = ''
460     if txt != ''
461         let txt = txt . ' '
462         while txt != ''
463             let one_dir = strpart(txt, 0, stridx(txt, ' '))
464             if find_prune != ''
465                 let find_prune = find_prune . ' -o'
466             endif
467             let find_prune = find_prune . ' -name ' . one_dir
468             let txt = strpart(txt, stridx(txt, ' ') + 1)
469         endwhile
470         let find_prune = '-type d ' . g:Grep_Shell_Escape_Char . '(' .
471                          \ find_prune
472         let find_prune = find_prune . ' ' . g:Grep_Shell_Escape_Char . ')'
473     endif
475     let txt = g:Grep_Skip_Files
476     let find_skip_files = '-type f'
477     if txt != ''
478         let txt = txt . ' '
479         while txt != ''
480             let one_file = strpart(txt, 0, stridx(txt, ' '))
481             let find_skip_files = find_skip_files . ' ! -name ' .
482                                   \ g:Grep_Shell_Quote_Char . one_file .
483                                   \ g:Grep_Shell_Quote_Char
484             let txt = strpart(txt, stridx(txt, ' ') + 1)
485         endwhile
486     endif
488     if g:Grep_Find_Use_Xargs == 1
489         let cmd = g:Grep_Find_Path . " " . startdir
490         let cmd = cmd . " " . find_prune . " -prune -o"
491         let cmd = cmd . " " . find_skip_files
492         let cmd = cmd . " " . find_file_pattern
493         let cmd = cmd . " -print | " . g:Grep_Xargs_Path . " " . grep_path
494         let cmd = cmd . " " . grep_opt . " -n "
495         let cmd = cmd . grep_expr_option . " " . pattern
496         let cmd = cmd . ' ' . g:Grep_Null_Device 
497     else
498         let cmd = g:Grep_Find_Path . " " . startdir
499         let cmd = cmd . " " . find_prune . " -prune -o"
500         let cmd = cmd . " " . find_skip_files
501         let cmd = cmd . " " . find_file_pattern
502         let cmd = cmd . " -exec " . grep_path . " " . grep_opt . " -n "
503         let cmd = cmd . grep_expr_option . " " . pattern
504         let cmd = cmd . " {} " . g:Grep_Null_Device . ' ' .
505                          \ g:Grep_Shell_Escape_Char . ';'
506     endif
508     call s:RunGrepCmd(cmd, pattern)
509 endfunction
511 " RunGrepSpecial()
512 " Search for a pattern in all the opened buffers or filenames in the
513 " argument list
514 function! s:RunGrepSpecial(cmd_name, which, ...)
515     if a:0 > 0 && (a:1 == "-?" || a:1 == "-h")
516         echo a:cmd_name . " [<grep_options>] [<search_pattern>]"
517         return
518     endif
520     " Search in all the Vim buffers
521     if a:which == 'buffer'
522         " Get a list of all the buffer names
523         let last_bufno = bufnr("$")
525         let i = 1
526         let filenames = ""
528         while i <= last_bufno
529             if bufexists(i) && buflisted(i)
530                 let filenames = filenames . " " . bufname(i)
531             endif
532             let i = i + 1
533         endwhile
535         " No buffers
536         if filenames == ""
537             return
538         endif
539     elseif a:which == 'args'
540         " Search in all the filenames in the argument list
541         let arg_cnt = argc()
543         if arg_cnt == 0
544             echohl WarningMsg
545             echomsg "Error: No filenames specified in the argument list "
546             echohl None
547             return
548         endif
550         let i = 0
551         let filenames = ""
553         while i < arg_cnt
554             let filenames = filenames . " " . argv(i)
555             let i = i + 1
556         endwhile
558         " No arguments
559         if filenames == ""
560             echohl WarningMsg
561             echomsg "Error: No filenames specified in the argument list "
562             echohl None
563             return
564         endif
565     endif
567     let grep_opt = ""
568     let pattern = ""
570     " Get the list of optional grep command-line options (if present)
571     " supplied by the user. All the grep options will be preceded
572     " by a '-'
573     let argcnt= 1
574     while argcnt <= a:0 && a:{argcnt} =~ '^-'
575         let grep_opt = grep_opt . " " . a:{argcnt}
576         let argcnt = argcnt + 1
577     endwhile
579     " If the user didn't specify the option, then use the defaults
580     if grep_opt == ""
581         let grep_opt = g:Grep_Default_Options
582     endif
584     " The last argument specified by the user is the pattern
585     if argcnt == a:0
586         let pattern = a:{argcnt}
587     else
588         " No argument supplied. Get the identifier and file list from user
589         let pattern = input("Search for pattern: ", expand("<cword>"))
590         if pattern == ""
591             return
592         endif
593     endif
595     let pattern = g:Grep_Shell_Quote_Char . pattern . g:Grep_Shell_Quote_Char
597     echo "\n"
599     " Add /dev/null to the list of filenames, so that grep print the
600     " filename and linenumber when grepping in a single file
601     let filenames = filenames . " " . g:Grep_Null_Device
602     let cmd = g:Grep_Path . " " . grep_opt . " -n -- "
603     let cmd = cmd . pattern . " " . filenames
605     call s:RunGrepCmd(cmd, pattern)
606 endfunction
608 " RunGrep()
609 " Run the specified grep command
610 function! s:RunGrep(cmd_name, grep_cmd, ...)
611     if a:0 > 0 && (a:1 == "-?" || a:1 == "-h")
612         echo a:cmd_name . " [<grep_options>] [<search_pattern> " .
613                         \ "[<file_name(s)>]]"
614         return
615     endif
617     let grep_opt  = ""
618     let pattern   = ""
619     let filenames = ""
621     " Parse the arguments
622     " grep command-line flags are specified using the "-flag" format
623     " the next argument is assumed to be the pattern
624     " and the next arguments are assumed to be filenames or file patterns
625     let argcnt = 1
626     while argcnt <= a:0
627         if a:{argcnt} =~ '^-'
628             let grep_opt = grep_opt . " " . a:{argcnt}
629         elseif pattern == ""
630             let pattern = g:Grep_Shell_Quote_Char . a:{argcnt} .
631                             \ g:Grep_Shell_Quote_Char
632         else
633             let filenames= filenames . " " . a:{argcnt}
634         endif
635         let argcnt = argcnt + 1
636     endwhile
638     if grep_opt == ""
639         let grep_opt = g:Grep_Default_Options
640     endif
642     if a:grep_cmd == 'grep'
643         let grep_path = g:Grep_Path
644         let grep_expr_option = '--'
645     elseif a:grep_cmd == 'fgrep'
646         let grep_path = g:Fgrep_Path
647         let grep_expr_option = '-e'
648     elseif a:grep_cmd == 'egrep'
649         let grep_path = g:Egrep_Path
650         let grep_expr_option = '-e'
651     elseif a:grep_cmd == 'agrep'
652         let grep_path = g:Agrep_Path
653         let grep_expr_option = '-e'
654     else
655         return
656     endif
658     " Get the identifier and file list from user
659     if pattern == "" 
660         let pattern = input("Search for pattern: ", expand("<cword>"))
661         if pattern == ""
662             return
663         endif
664         let pattern = g:Grep_Shell_Quote_Char . pattern .
665                         \ g:Grep_Shell_Quote_Char
666     endif
668     if filenames == ""
669         let filenames = input("Search in files: ", g:Grep_Default_Filelist)
670         if filenames == ""
671             return
672         endif
673     endif
675     echo "\n"
677     " Add /dev/null to the list of filenames, so that grep print the
678     " filename and linenumber when grepping in a single file
679     let filenames = filenames . " " . g:Grep_Null_Device
680     let cmd = grep_path . " " . grep_opt . " -n "
681     let cmd = cmd . grep_expr_option . " " . pattern
682     let cmd = cmd . " " . filenames
684     call s:RunGrepCmd(cmd, pattern)
685 endfunction
687 " Define the set of grep commands
688 command! -nargs=* Grep       call s:RunGrep('Grep', 'grep', <f-args>)
689 command! -nargs=* Rgrep      call s:RunGrepRecursive('Rgrep', 'grep', <f-args>)
690 command! -nargs=* GrepBuffer call s:RunGrepSpecial('GrepBuffer', 'buffer',
691                                                  \ <f-args>)
692 command! -nargs=* Bgrep      call s:RunGrepSpecial('Bgrep', 'buffer', <f-args>)
693 command! -nargs=* GrepArgs   call s:RunGrepSpecial('GrepArgs', 'args',
694                                                  \ <f-args>)
696 command! -nargs=* Fgrep      call s:RunGrep('Fgrep', 'fgrep', <f-args>)
697 command! -nargs=* Rfgrep     call s:RunGrepRecursive('Rfgrep', 'fgrep',
698                                                    \ <f-args>)
699 command! -nargs=* Egrep      call s:RunGrep('Egrep', 'egrep', <f-args>)
700 command! -nargs=* Regrep     call s:RunGrepRecursive('Regrep', 'egrep',
701                                                    \ <f-args>)
702 command! -nargs=* Agrep      call s:RunGrep('Agrep', 'agrep', <f-args>)
703 command! -nargs=* Ragrep     call s:RunGrepRecursive('Ragrep', 'agrep',
704                                                    \ <f-args>)
706 " restore 'cpo'
707 let &cpo = s:cpo_save
708 unlet s:cpo_save