O'Reilly logo

Mastering Vim by Ruslan Osipov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Searching across files

Vim has two commands to help you search across files, :grep and :vimgrep:

  • :grep uses system grep, and is a great tool if you're already familiar with how grep works
  • :vimgrep is a part of Vim, and might be easier to use if you are not already familiar with grep

We'll focus on :vimgrep, since the grep tool is outside the scope of this book.

The syntax is as follows: :vimgrep <pattern> <path>. pattern could either be a string or a Vim-flavored regular expression. path will often be a wildcard; use ** as a path to search recursively (or **/*.py to restrict by filetype).

Let's try searching for a calc substring in our code base:

:vimgrep animal **/* .py

This will take us to the first match, displaying the number of matches ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required