Searching for literal text
Vim’s search functionality supports a rich regular expression language. But, as we mentioned in the last section, we’re going to explore that in another lesson.
If you’re familiar with regular expressions already, though, you’ll know that certain characters have special meanings. The . character, for example, will match any character when used in a search pattern. If we initiate a search with /., it will match every character in the document.
Try this in the editor. Initiate a search with /., then hit enter. You’ll notice that every character is highlighted.
Well, what if we want to search for a literal . character? Our first option is to escape the . with \. — so our search command would look like /\.. This works, but \ is kind of difficult to type, and if we want to search for something like ... then it gets even more cumbersome.
The best option here is to tell Vim that we want to search for a literal string — i.e. not a regular expression — by prefixing our search term with \V. This tells Vim not to use the special regex meanings for characters in our search, and to treat them as literal text. If we specify \V, only a backslash and the terminating character (usually / or ?) have special meaning.
Try this in the editor. Initiate a new search with /, and immediately type \V. Everything you type thereafter will be treated as a literal character. Use this to find the only instance of HAYST.CK in the document.