← All lessons

8. Searching

Step 1 of 7

Searching with Vim

Using the search functionality in your text editor is often the fastest way to get where you want — especially if the document you’re working in is large.

Vim has an extremely powerful search function that also supports a rich regular expression language. In this lesson, we’re going to explore how to actually perform searches. We’re going to leave the regular expression stuff for a later lesson, because there’s a lot to cover!

There are two ways that you can start a search in Vim: using either the / or ? key in normal mode. Both of these keys enter the search prompt, where you can type in a regular expression or a literal string — the difference is that / starts searching forward and ? starts searching backwards.

In both cases, when you’re done, hit the enter key to initiate your search and return to normal mode.

Try this in the editor. The editor is pre-populated with lines containing the word HAYSTACK. Your task is to find the only line containing the word NEEDLE. The file is 100,000 lines long, so you have to use search!

Loading editor…