Search for an exact word in Vim command mode

20

7

I want to search for an exact word in Vim in command mode (using Vim command /wordtosearch, NOT the search of the current word at the cursor using * or # commands), e.g. I would like to search for an exact word say CIF but I do not want to find CIF_handle or CIF_drv.

How to make Vim search for exact word in the command mode?

(I don't mind the case of the word searched, because I already have ignorecase set.)

goldenmean

Posted 2010-10-29T10:06:37.317

Reputation: 2 087

Answers

31

Use regular expressions:

/\<your_exact_word\>

In other words, enclose your search string between \< and \>

Janne Pikkarainen

Posted 2010-10-29T10:06:37.317

Reputation: 6 717

Doesn't work with brackets. – None – 2017-07-06T14:52:18.533

@Thanks: workd nicely. Does enclosing the word in < .. > make it a regex based search. – goldenmean – 2010-10-29T10:19:30.403

Yes, it's a regex search. – Janne Pikkarainen – 2010-10-29T10:22:04.800

How do you configure vim to behave with an exact word search without needing to wrap it with \< and \> char. Can vim be made to do exact word search by /eightFoldPaths ? – typelogic – 2019-09-14T21:43:10.150

But what do u do if u need to search for a string like "1...". It will highlight all numbers starting with 1 and not the string with the dots. – scigor – 2012-11-09T10:43:21.047

-1

I just had tried to use /\<*> to search literally * sign in vim, obviously it also counted space in the list. here is the possible way to do it in a Very Nomagic way,

/\v*

for for more detail :help \V

Ponderous

Posted 2010-10-29T10:06:37.317

Reputation: 1

1Sorry, but this is not an answer to the question stated. If you want to add information to the accepted answer, you may want to add a comment over there. – Edward – 2016-08-23T08:05:31.550