Reputation: 31
In order to substitute some columns of a table written in latex in vim, I write a regex to help me perform this work. The regex is:
s/\v^(\d+ &)( \d+ &)( \d+ &)/\1\3\2/g
And I want it to match the lines like these below:
10 & 25 & 25 & 100\\
7 & 56 & 56 & 100\\
However, this regex never works. Vim keeps telling me this pattern could not be found. But I have already used the very magic mode and this regex does work elsewhere, see https://regex101.com/r/DBwTHM/1.
Could anyone help me please? Thanks a lot!
Upvotes: 0
Views: 68
Reputation: 10580
In Vim's "very magic" mode you need to escape each ampersand &
with a backslash \
.
:%s/\v^(\d+ \&)( \d+ \&)( \d+ \&)/\1\3\2/g
Upvotes: 3
Reputation: 196886
I've always found "verymagic" too troublesome.
:s/^\(\d\+\) & \(\d\+\) & \(\d\+\)/\1 \& \3 \& \2
Upvotes: 1