vim Searching For Pattern


Vim supports the use of regular expressions when searching through a file.

The character to indicate that you wish to perform a search is /.

The simplest search you can perform is the following


This will search the entire file for all instances of if. However, our search if is actually a regular expression that will match any occurrence of the word if including those inside of other words.

For instance, our search would say all of the following words match our search: if, spiffy, endif, etc.

We can do more complicated searches by using more complicated regular expressions.

If our search was:


then our search would only return exact matches to the full word if. The above spiffy and endif would not be returned by the search, only if.

We can also use ranges. Given a file:


If we want to search for those lines containing "hello" followed by a digit between 1 and 3 we would say:


Another example:


would find all of the integer and decimals numbers in the file.