How to Search in Vim

· 160 words · 1 min

The basic steps to perform a search in Vim are as follows:
  1. Press /.
  2. Type the search pattern.
  3. Press Enter to perform the search.
  4. Press n to find the next occurrence or N to find the previous occurrence.

Search for Whole Word

To search for a whole word, type \< to mark the beginning of a word, enter the search pattern, type \> to mark the end of a word, and hit Enter to perform the search.

For example, to search for “gnu” you would use /\<gnu\>.

Search the Current Word

You can also search for a whole word by moving the cursor to the word and pressing * to search forwards or # to search backwards. To find the next match press * or # again.

Search History

Vim keeps track of all the search operations you made in the current session. To browse the search history, press / and use the arrow up/down keys to find a previous search operation. To run the search, simply press Enter. You can also edit the search pattern before performing the operation.