One way to fix this is by ensuring the pattern is enclosed by escaped parentheses:
:%s/\(\w\)\(\w\w\)/\1y\2/g
Slightly shorter (and more magic-al) is to use \v
, meaning that in the pattern after it all ASCII characters except '0'-'9'
, 'a'-'z'
, 'A'-'Z'
and '_'
have a special meaning:
:%s/\v(\w)(\w\w)/\1y\2/g
:help \(
:help \v
If you don't want to escape the capturing groups with backslashes (this is what you've missed), prepend \v
to turn Vim's regular expression engine into very magic mode:
:%s/\v(\w)(\w\w)/\1y\2/g
You can also use this pattern which is shorter:
:%s/^./&y
%s
applies the pattern to the whole file.^.
matches the first character of the line.&y
adds the y
after the pattern.You also have to escape the Grouping paranthesis:
:%s/\(\w\)\(\w\w\)/\1y\2/g
That does the trick.
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