2

I was editing a file and found accidentally that I somehow escaped all the forward slashes in a path I was replacing in text. And that is something very useful!

For instance, to do this replacement correctly I should escape the second path:

:%s/mvn//opt/maven/bin/mvn/g

I did that somehow with an accidental keystroke! But which one? :-(

Thank you.

ruohola
  • 666
  • 5
  • 20
janux
  • 21
  • 2
  • Related issue: https://vi.stackexchange.com/questions/3156/what-does-it-mean-to-replace-slashes-by-exclamation-marks-in-a-substitut – Hotschke Aug 03 '19 at 09:50

1 Answers1

9

You don't need to escape them: you could use a different separator for the search pattern and the replace part:

%s;mvn;/opt/maven/bin/mvn;g

But, if you really want to escape them, you can use a backslash (\):

%s/mvn/\/opt\/maven\/bin\/mvn/g

(much harder to read, IMO)

João A. Toledo
  • 773
  • 5
  • 11