user2327201
user2327201

Reputation: 409

Vi search and replace with slashes

I am trying to run this command in vi

:s/href="\//href="http:\/\/website.com\/folder\/subfolder\//g

but got this error E486: Pattern not found: href="\/

What am i doing wrong?

Upvotes: 2

Views: 1795

Answers (3)

ptierno
ptierno

Reputation: 10074

On another note. That substition worked for me. Just copied and pasted. Are you on the same line that you are trying to perform the substitution on? the 'g' is meant globally on the line you are on. If you need to perform the search and replace on the file the use :%s/

Upvotes: 0

Marcin Fabrykowski
Marcin Fabrykowski

Reputation: 619

becouse there are many '/' chars, try use another delimiter, ex ',':

:s,some/pattern/with/slashes,new/string,g

Upvotes: 1

lreeder
lreeder

Reputation: 12206

That error means pretty much what it says. vi didn't find any pattern href="/ (ignoring escapes) in your file.

Sometimes it's easier to use something besides / for the search delimiter if your search has a lot of slashes, so you don't need to escape them all. Try replacing the / delimiter with # instead, like this:

s#href="/#href="http://website.com/folder/subfolder/#g

Then maybe you can more easily see what's wrong with your pattern:

Upvotes: 2

Related Questions