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 with / and ?

Most times one of the fastest ways to navigate somewhere is to search for a particular string. Vim allows you to search for a match by typing in / (which puts you in command-line mode) followed by a search string. Once you hit Enter, your cursor will move to the first match.

Cycling through the matches in the same buffer can be done by pressing n to go to the next match and N to the previous match.

A useful option for searching is set hlsearch (consider setting it in your .vimrc file), since it highlights every match on the screen. For example, this is how running /kind in animal_farm.py looks with hlsearch enabled:

You can clear the highlights by executing :noh.

Another nifty trick is using set incsearch. This will ...

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