Tip 110: Grep with Vim's Internal Search Engine
Return to the top: <<Practical Vim>>
:vim[grep][!] /{pattern}/[g][j] {file} ...
-
When multiple matches are on the same line, the presence of the
g
flag creates a match for each one of them. Without it, only a single record is created for the entire line. -
By default, Vim will jump straight to the first match, but you can prevent this by including the
j
flag. -
The
{file}
argument must not be blank. -
It can accept the same parameters as the
:args
command. -
##
is expanded to represent the names of each file in the argument list.
References:
# If you open the file in vim, # then you can \"ayy@a the next line to execute the vim command: :h :_##
Search in File, Then Search in Project
-
main advantage to using
:vimgrep
: it understands the same patterns as Vim’s search command
Example:
/\v'(([^']|'\w)+)' :vim /<C-r>// **
Search History and :vimgrep
If the pattern field is empty, the :vimgrep
command matches every line in every file that it looks inside.