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
/if
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:
/\<if\>
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:
hello1
hello2
hello3
hello4
If we want to search for those lines containing "hello" followed by a digit between 1 and 3 we would say:
/hello[1-3]
Another example:
/(?:\d*\.)?\d+
would find all of the integer and decimals numbers in the file.