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?
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:
Verify with
:ver
that+perl
or+perl/dyn
is compiled in.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.
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With