Reputation: 1429
I am trying to replace multiple forward slashes "//" with a single slash "/".
How would you do that?
Also, How would you replace "asd/qwe/zxc" with "fgh/vbn"?
I was able to do this half way using below. But how do I use forward slash in the search string or the replace string.
:%s/asd.qwe.zxc/fgh/g
Upvotes: 6
Views: 4132
Reputation:
:%s/\/\//\#/gc
It replaces OpenSCAD comment (//) to Python comment (#).
// Faces: 60
F = [
[ 0, 1, 2], // 0
[ 1, 3, 4], // 1
[ 1, 4, 2], // 2
[ 2, 4, 5], // 3
[ 0, 2, 6], // 4
# Faces: 60
F = [
[ 0, 1, 2], # 0
[ 1, 3, 4], # 1
[ 1, 4, 2], # 2
[ 2, 4, 5], # 3
[ 0, 2, 6], # 4
Upvotes: 0
Reputation: 7144
Try this
Esc :
:1,$s/asd\/qwe\/zxc/fgh\/vbn/g
You need to escape '/' using backslash '\' .
Upvotes: 1
Reputation: 37279
You can try using:
:%s/\/\//\//g
to replace all double slashes with single slashes (though I imagine a guru will show a much cooler way shortly :) ). The general idea is that you need to escape the slashes.
Upvotes: 2
Reputation: 59633
Either escape it or use different delimiters.
:s/\/\//\//g
:s#//#/#g
I prefer the latter.
Missed the second part:
:s/asd\/qwe\/zxc/fgh\/vbn/g
:s@asd/qwe/zxc@fgh/vbn@g
You can pick any delimiter that you want in the same manner that you could in ed
or sed
.
Upvotes: 13