kortina
kortina

Reputation: 6101

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

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

Upvotes: 194

Views: 42061

Answers (4)

Luke Girvin
Luke Girvin

Reputation: 13432

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

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

/the\>/

Upvotes: 109

Prasanna Natarajan
Prasanna Natarajan

Reputation: 772

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

Upvotes: 47

Rocky
Rocky

Reputation: 5716

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

Upvotes: 18

Related Questions