34

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.)

2 Answers 2

52

Use regular expressions:

/\<your_exact_word\>

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

5
  • @Thanks: workd nicely. Does enclosing the word in \< .. \> make it a regex based search.
    – goldenmean
    Oct 29, 2010 at 10:19
  • Yes, it's a regex search. Oct 29, 2010 at 10:22
  • 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
    Nov 9, 2012 at 10:43
  • Doesn't work with brackets.
    – user530079
    Jul 6, 2017 at 14:52
  • 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 ?
    – daparic
    Sep 14, 2019 at 21:43
-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

1
  • 1
    Sorry, 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
    Aug 23, 2016 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.