Using /
or ?
enables to find a match for a word in vim. But how can I find an exact match?
For example, my text contains the following words: a a
To find a single, standalone aa
(not a
, aaa
, ...), you need to assert no match of that character both before and afterwards. This is done with negative lookbehind (\@ in Vim's regular expression syntax) and lookahead (
\@!
) enclosing the match itself (a\{2}
):
/\%(a\)\@
Those assertions are hard to type, if the border around the match is also a non-keyword / keyword border, you can use the shorter \<\a\{2}\>
assertions (as in MosteM's answer), but this doesn't work in the general case, e.g. with xaax
.