Discussion:
vim - search <br>and replace by a line break character
(too old to reply)
Onix
2006-06-12 00:49:45 UTC
Permalink
Hi, I have an HTML document that needs to replace all of its "<br>"
tags to a normal line break. But my command of :%s/<br>/\n/g seems not
useful at all. How can I do this? thanks.
Bob Stearns
2006-06-12 01:05:11 UTC
Permalink
Post by Onix
Hi, I have an HTML document that needs to replace all of its "<br>"
tags to a normal line break. But my command of :%s/<br>/\n/g seems not
useful at all. How can I do this? thanks.
If you want a real line break, use <ctrl-v><ctrl-m>. Under windows,
<ctrl-q><ctrl-m>, not \n.
Gary Johnson
2006-06-12 06:48:52 UTC
Permalink
Post by Onix
Hi, I have an HTML document that needs to replace all of its "<br>"
tags to a normal line break. But my command of :%s/<br>/\n/g seems not
useful at all. How can I do this? thanks.
Vim uses '\n' for a newline in patterns, but '\r' for a newline in
replacement strings. So changing your command to

:%s/<br>/\r/g

should do the trick. See

:help sub-replace-special

Gary
quarkLore
2006-06-12 08:35:21 UTC
Permalink
One can also use sed

sed 's/<br>/\n/g' file.html > outputfile.html

vi can have macros which are a better options for using an editor
Loading...