Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 427
einpoklum Avatar asked Oct 12 '15 12:10

einpoklum


1 Answers

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'

like image 91
Wiktor Stribiżew Avatar answered Sep 30 '22 03:09

Wiktor Stribiżew