Can I make vim accept \b rather than just \< and>?

前端 未结 1 1074
无人及你
无人及你 2021-01-19 03:34

I\'ve just read this:

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

and I was wondering - can\'t I make vim recognize

相关标签:
1条回答
  • 2021-01-19 04:02

    Since Vim's regex flavor treats \b as a backspace character, and there is no chance re-defining this shorthand construct, you can only make it work with a PCRE regex engine that can be used with Vim the way described at Perl compatible regular expressions Vim Tips Wiki.

    This is the description from that page:

    1. Verify with :ver that +perl or +perl/dyn is compiled in.

    2. Install Perl if necessary. On Windows, ActivePerl is standard but any dependency-free perl58.dll will work if you don't need any other perl modules. If you don't want a full install of perl, copy perl58.dll from Strawberry Perl 5.8.x into the folder vim.exe lives and the commands below will work.

    3. Type :perldo s/searchme/replaceme/g

    Note: +perl/dyn doesn't seem to be necessary.

    Or if Ruby is compiled in, Ruby's regex can be used, too to recognize \b as a word boundary:

    Or if you have ruby compiled in (look for +ruby in :ver output)

    Equivalent to s/pattern/replacement/g:

    :rubydo gsub /pattern/,'replacement'

    0 讨论(0)
提交回复
热议问题