Tried
:s/\\\/\\/g
but VIM will search for \\/\
instead.
So is there any way I can do this in Vim?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityIn s/\\\/\\/
:
\
escapes the second \
; \
is escaped, so it's no longer special; and\
isn't escaped, so it escapes the /
after it.So you need to escape the third \
like the second was:
:s/\\\\/\\/g
\
escapes the next character, unless it is itself escaped by a \
. There are a lot of exceptions. See :h pattern-atoms
for some of those
\
isn't escaped by the 1st. The 2nd is escaped by the 1st and the 4th is escaped by the 3rd.
:1,$:s/\\\\/\\/g
1 means the first line and $ means till the last one.
each \\
means \
, and \/
removes the /
as divider, here you have your syntax error.
:s/\\\/\\/g
uses \\\/\\
as the pattern and g
as the replacement. (A trailing /
is implied.)
\
or/
, I often use#
as a delimiter for the substitute command because this is more easy to grasp visually (I feel), i.e.:s#\\\\#\\#g