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

为君一笑 提交于 2019-12-04 03:30:06

问题


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 \b also, somehow?


回答1:


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'



来源:https://stackoverflow.com/questions/33081331/can-i-make-vim-accept-b-rather-than-just-and

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!