You are not logged in.
How do I wrap <p> </p> tags around paragraphs globally??
And when I try to wrap <i></i> around a line, i get the error E488: trailing characters.
:28,32s/.*/<i>&</i>/g
. I thought this would wrap italic markers around the whole lines from 28 to 32, what am I doing wrong?
Oh, and if anyone has a link to a good tutorial for n00bs on global substitutions by regular expressions, don't keep it to yourselves. :-)
Last edited by Reploid (2009-03-06 18:39:35)
Offline
How do I wrap <p> </p> tags around paragraphs globally??
And when I try to wrap <i></i> around a line, i get the error E488: trailing characters.
:28,32s/.*/<i>&</i>/g
. I thought this would wrap italic markers around the whole lines from 28 to 32, what am I doing wrong?
Oh, and if anyone has a link to a good tutorial for n00bs on global substitutions by regular expressions, don't keep it to yourselves. :-)
You have to escape the / in </i>, or use another delimiter.
Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest
Offline
28,37s/.*/<i>&<\/i>/g
It worked!! This will same me of TONS of time, yay! Thanks!!!!
What would I put in there to signal that I want to replace a paragraph?
EDIT: cheated a little:
:%s /^$/<\/p><p>
inserting the paragraph markers on the blank lines instead of around paragraphs, and just inserting the first <p> manually.
Last edited by Reploid (2009-03-06 22:19:56)
Offline
Take a look at http://www.vim.org/scripts/script.php?script_id=1697
Offline
Thx @ Husio. Will experiment with script a little later, trying to learn the basic stuff for now.
Another question:
I have sentences like:
<p><span class=font25>4th completely revised edition</span></p>
However, I can only seem to substitute the sentences with font0-9. (!)
This doesn't work:
:%s<span class=font[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,2
5,26,27,28,29,30]\+><b>\(.*\)<\/b><\/span>/\1/
This doesn't work:
:%s<span class=font[0-9][0-9]*>
This doesn't work:
<span class=font[0-9*][0-9*]>
What would help me get rid of the formatting markup??
Last edited by Reploid (2009-03-08 12:54:02)
Offline
Do you want to get rid of all tags?
Try this:
:%s/<[^>]*>//g
Offline
EDIT: I just wanted to remove a few types of tags, but by modifying your script a little, I could make it work by a few keypresses. Thank you so VERY VERY much.
(I did
:%s/<span[^>]*>//g
and:
:%s/<\/span[^>]*>//g
)
But, seeing as I am trying to learn this stuff, and not just have ppl script for me, how would I go about to include a range from 0-99 in my pattern? [0-9][0-9] didn't work??
Another thing that I spent the entire yesterday, trying to figure out, was how to take the name "super heading" and create "super_heading.html" out of it, making it apply to all the "super duper duper headings" as well.
Last edited by Reploid (2009-03-08 14:15:48)
Offline
[0-9]+ will match any number, any amount of characters (at least one).
archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson
Offline
rson451, that doesn't seem to work.
I created a testfile to eliminate the chance of me typing something unintentionally looking just like this:
font
font23
font55
font1
font9
font8
... and then I type
:%s/font[0-9]+/I love reg ex/
It does not replace the font23, font1 etc with "I love reg ex" , it just spits out E486: pattern not found: font[0-9]+
Offline
in :s it has to be \+
:%s/[0-9]\+/99/g should work
same as :%s/[0-9][0-9]*/99/g
The biggest problem is that regex is greedy, and that doesn't go well with html/xml.
So in tags matching for [^>]* is important.
About issue 2, if you take
<h1>s u m m e r holiday</h1>
And want to convert it to
<a href="s_u_m_m_e_r_holiday">s u m m e r holiday</a>
I don't know actually. I think vim is lacking strength.
You should try to do it with sed.
sed '{s~<h1>\([^<]*\)</h1>~\1~;T;h;s~ ~_~g;s~.*~<a href="&">~;G;s~$~</a>~;s~\n~~}' FILE.html
Offline
The \+ worked, so I must have done something else wrong before, as I tried the \+ on my huge textfile. But the other solution you presented was a lot more elegant, so I'll just stick with that. I read a bit about the greedy stuff in the O'Reilly textbook, so I'll brush up on that to consolidate what I've learned so far. As for the underscore, well, at least I know there is a reason why I couldn't find something applying.
Thx 4 helping me out.
Offline