PracticalVim Tip110 - yszheda/wiki GitHub Wiki

Table of Contents

Tip 110: Grep with Vim's Internal Search Engine

Return to the top: <>

  • 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:

Search in File, Then Search in Project

  • main advantage to using `:vimgrep`: it understands the same patterns as Vim’s search command
Example:

Search History and `:vimgrep`

If the pattern field is empty, the `:vimgrep` command matches every line in every file that it looks inside.

⚠️ **GitHub.com Fallback** ⚠️