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

后端 未结 4 971
醉酒成梦
醉酒成梦 2020-12-02 07:14

I\'d like to be able to search

/the\\b

to find \"the\" but not \"then\".

I also tried searching with very magic turne

相关标签:
4条回答
  • 2020-12-02 07:55

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

    0 讨论(0)
  • 2020-12-02 07:58

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

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

    /the\>/
    
    0 讨论(0)
  • 2020-12-02 08:03

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

    0 讨论(0)
  • 2020-12-02 08:04

    /the\>

    See :help /ordinary-atom

    I assume "regexp" means PCRE. It is worth noting that Vim's regex syntax differs from (and apparently predates) PCRE.

    See also:

    • Why does VIM have its own regex syntax?
    • What's the difference between vim regex and normal regex?
    • Within vim's regex engine, why are some metacharacters escaped and some are not?
    • Can I make vim accept \b rather than just \< and \>?
    0 讨论(0)
提交回复
热议问题