used.
- When plugins are enabled: compressed and remote files can be searched.
|gzip| |netrw|
To be able to do this Vim loads each file as if it is being edited. When
there is no match in the file the associated buffer is wiped out again. The
'hidden' option is ignored here to avoid running out of memory or file
descriptors when searching many files. However, when the |:hide| command
modifier is used the buffers are kept loaded. This makes following searches
in the same files a lot faster.
Note that |:copen| (or |:lopen| for |:lgrep|) may be used to open a buffer
containing the search results in linked form. The |:silent| command may be
used to suppress the default full screen grep output. The ":grep!" form of
the |:grep| command doesn't jump to the first match automatically. These
commands can be combined to create a NewGrep command: >
command! -nargs=+ NewGrep execute 'silent grep! <args>' | copen 42
5.1 Using Vim's internal grep
*:vim* *:vimgrep* *E682* *E683*
:vim[grep][!] /{pattern}/[g][j][f] {file} ...
Search for {pattern} in the files {file} ... and set
the error list to the matches. Files matching
'wildignore' are ignored; files in 'suffixes' are
searched last.
{pattern} is a Vim search pattern. Instead of
enclosing it in / any non-ID character (see
|'isident'|) can be used, so long as it does not
appear in {pattern}.
'ignorecase' applies. To overrule it put |/\c| in the
pattern to ignore case or |/\C| to match case.
'smartcase' is not used.
If {pattern} is empty (e.g. // is specified), the last
used search pattern is used. |last-pattern|
Flags:
'g' Without the 'g' flag each line is added only
once. With 'g' every match is added.
'j' Without the 'j' flag Vim jumps to the first
match. With 'j' only the quickfix list is
updated. With the [!] any changes in the current
buffer are abandoned.
'f' When the 'f' flag is specified, fuzzy string
matching is used to find matching lines. In this
case, {pattern} is treated as a literal string
instead of a regular expression. See
|fuzzy-matching| for more information about fuzzy
matching strings.
|QuickFixCmdPre| and |QuickFixCmdPost| are triggered.
A file that is opened for matching may use a buffer
number, but it is reused if possible to avoid
consuming buffer numbers.
:{count}vim[grep] ...
When a number is put before the command this is used
as the maximum number of matches to find. Use
":1vimgrep pattern file" to find only the first.
Useful if you only want to check if there is a match
and quit quickly when it's found.
Every second or so the searched file name is displayed
to give you an idea of the progress made.
Examples: >
:vimgrep /an error/ *.c
:vimgrep /\<FileName\>/ *.h include/*
:vimgrep /myfunc/ **/*.c
< For the use of "**" see |starstar-wildcard|.
:vim[grep][!] {pattern} {file} ...
Like above, but instead of enclosing the pattern in a
non-ID character use a white space separated pattern.
The pattern must start with an ID character.
Example: >
:vimgrep Error *.c
<
*:lv* *:lvimgrep*
:lv[imgrep][!] /{pattern}/[g][j][f] {file} ...
:lv[imgrep][!] {pattern} {file} ...
Same as ":vimgrep", except the location list for the
current window is used instead of the quickfix list.
*:vimgrepa* *:vimgrepadd*
:vimgrepa[dd][!] /{pattern}/[g][j][f] {file} ...
:vimgrepa[dd][!] {pattern} {file} ...
Just like ":vimgrep", but instead of making a new list
of errors the matches are appended to the current
list.
*:lvimgrepa* *:lvimgrepadd*
:lvimgrepa[dd][!] /{pattern}/[g][j][f] {file} ...
:lvimgrepa[dd][!] {pattern} {file} ...
Same as ":vimgrepadd", except the location list for
the current window is used instead of the quickfix
list.
5.2 External grep
Vim can interface with "grep" and grep-like programs (such as the GNU