In Vim, how do you search for a word boundary character, like the \b in regexp?

Vim

Vim Problem Overview


I'd like to be able to search

/the\b

to find "the" but not "then".

I also tried searching with very magic turned on:

/\vthe\b

Vim Solutions


Solution 1 - Vim

Solution 2 - Vim

Use \< and \> for word start and word end, respectively.

E.g. In your specific case you would use:

/the>/

Solution 3 - Vim

If very magic is turned on, then you shouldn't escape the > character. See what's magic search. SO in your case you'd do:

/\v<the>

it would search for only the word 'the'.

Solution 4 - Vim

if you are trying to search a word at your cursor. you can just hit *, or # for backward search.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionkortinaView Question on Stackoverflow
Solution 1 - VimAdam MonsenView Answer on Stackoverflow
Solution 2 - VimLuke GirvinView Answer on Stackoverflow
Solution 3 - VimPrasanna NatarajanView Answer on Stackoverflow
Solution 4 - VimRockyView Answer on Stackoverflow