Re: multi line regex's in vi ...
On Sat, Apr 29, 2000 at 08:13:21PM -0700, Rick Younie wrote: On Sat, Apr 29, 2000, Adam Shand wrote: A two-liner is %s/^/p/ - add p to the start of each line %s/^p$// - remove any lines that contain only p nope won't work. it'll put a 'p ' at the beginning of every line which has text in it. thus this: Ah. Don't know how to do that with regex's but you can get it done with record/playback with Vim and Elvis. You probably already know this. qa - start recording to register a /^$ - go to first blank line cursor down insert and type P esc q - stop recording [EMAIL PROTECTED] - repeats the recorded keystrokes a bunch of times If you have multiple adjacent blank lines you'll need to squash them to one, :g/^$/,/./-j Gotta be an easier way though. Maybe one of the vi pros will drop in. Rick -- I'm no pro, but the following, without squashing works. And yes, I know that at the end of the file it might give an error. :g/^ *$/+1 s/^ *[^ ]/p/ John
Re: multi line regex's in vi ...
that's useful, thanks. i've never used macro's in vi, i'll play with it. i need to check out wml as well as someone else suggested ;) adam. On Sat, 29 Apr 2000, Rick Younie wrote: On Sat, Apr 29, 2000, Adam Shand wrote: A two-liner is %s/^/p/ - add p to the start of each line %s/^p$// - remove any lines that contain only p nope won't work. it'll put a 'p ' at the beginning of every line which has text in it. thus this: Ah. Don't know how to do that with regex's but you can get it done with record/playback with Vim and Elvis. You probably already know this. qa - start recording to register a /^$ - go to first blank line cursor down insert and type P esc q - stop recording [EMAIL PROTECTED] - repeats the recorded keystrokes a bunch of times If you have multiple adjacent blank lines you'll need to squash them to one, :g/^$/,/./-j Gotta be an easier way though. Maybe one of the vi pros will drop in. Rick -- -- Unsubscribe? mail -s unsubscribe [EMAIL PROTECTED] /dev/null
Re: multi line regex's in vi ...
I'm no pro, but the following, without squashing works. And yes, I know that at the end of the file it might give an error. :g/^ *$/+1 s/^ *[^ ]/p/ that does indeed do the trick! now i just have to decipher the regex so i understand it. thanks! adam.
Re: multi line regex's in vi ...
Adam Shand wrote: clever solution. wish i'd come up with that one. ain't that always the way ... :) here's the lo-down: :g - globally--i.e. thru every line in the file how is that different from :s/find/replace/g ? ex is a LINE editor. if your line looks like this: life is like a box of chocolates you can issue s/ /-/g to turn it into life-is-like-a-box-of-chocolates that is, s///=substitute on this line, /g=globally ON THIS LINE (all instances get replaced). whereas :g denotes 'repeat on all LINES of the file' so a :g s/// will, on EACH LINE, replace the FIRST instance of whatever; to replace all instances on each line you need to use :g s///g /^ *$/ - for every line that is blank (zero or more spaces only) +1 - increment line counter (i.e. go to line following match!) so this just moves it down a line right? it finds the empty line and then goes down one. right. s/^ * - look for blanks at beginning of line [^ ]/ - that are followed by a non-blank p- replace with a p / - and the string that was matched so is a short hand way of using ()'s and \1? tha's my guess (i'm not absolutely positive, but the documentation will clarify that, i'm sure). of course if you have two blank lines in a row, it breaks... it'll just put the 'p' at the beginning of the second blank line right? is it possible to do two searches instead of incrementing the line counter? ie. search for ^ *$ and then search for ^[^ ] so you are guarenteed to be at the next line of no. on the s/// part, he had it look for non-blanks, which makes it fail when it encounters a second blank line in a row: :g/^ *$/+1 s/^ *[^ ]/p/ if you always have single blank lines (even with spaces on them) this'll work, but it perishes when there's two in a row. (probably better long-term solution is to use perl (or wml) to filter your text.) yeah, i'm checking out wml now, though with this solution i actually don't have a lot of need for one. if you're just bringing a one-shot website from text to html, then you're probably right. but if you do this kind of thing often, either perl or wml (which uses perl, as i recall) will save your bacon many times over...
Re: multi line regex's in vi ...
So add p to any non-blank line? I'd like to know a one-liner for this too. You've got blank line with ^$ but how do you negate that? but what if a paragraph has more then one line. you have to detect the beginning of a new paragraph and then insert a 'p ' before the first line of text. A two-liner is %s/^/p/ - add p to the start of each line %s/^p$// - remove any lines that contain only p nope won't work. it'll put a 'p ' at the beginning of every line which has text in it. thus this: one lineladf aflkasd flaskdjf alskdfj alskdfja lskdjf alskdjf alsdkfj lasdkfj alkjdfalskjdf laskdfj laskdjf laksdjf alksjf ald lkadjflaksdjf laklj and the end of aldkfja ladkfj alksdjf oqieruoqiewjrlkdmflk adlf ladfj ladkf alkdjf lakd flaksdj flaksdfj. will become this: pone lineladf aflkasd flaskdjf alskdfj alskdfja lskdjf alskdjf alsdkfj plasdkfj alkjdfalskjdf laskdfj laskdjf laksdjf alksjf ald lkadjflaksdjf plaklj and the end of aldkfja ladkfj alksdjf oqieruoqiewjrlkdmflk adlf pladfj ladkf alkdjf lakd flaksdj flaksdfj. adam.
Re: multi line regex's in vi ...
On Sat, Apr 29, 2000, Adam Shand wrote: A two-liner is %s/^/p/ - add p to the start of each line %s/^p$// - remove any lines that contain only p nope won't work. it'll put a 'p ' at the beginning of every line which has text in it. thus this: Ah. Don't know how to do that with regex's but you can get it done with record/playback with Vim and Elvis. You probably already know this. qa - start recording to register a /^$ - go to first blank line cursor down insert and type P esc q - stop recording [EMAIL PROTECTED] - repeats the recorded keystrokes a bunch of times If you have multiple adjacent blank lines you'll need to squash them to one, :g/^$/,/./-j Gotta be an easier way though. Maybe one of the vi pros will drop in. Rick --
Re: multi line regex's in vi ...
In article [EMAIL PROTECTED] you wrote: is there a way to match a pattern over more then one line in vi (i normally use vim)? i'm html formatting text documents and what i'd like to do is replace something like the below paragraphs: __ the first line of text, this is really boring, blah lah blh why do i care. html formatting text is really boring and vi saves me. the is a second line of text. __ with something like this __ p the first line of text, this is really boring, blah lah blh why do i care. html formatting text is really boring and vi saves me. p the is a second line of text. __ So add p to any non-blank line? I'd like to know a one-liner for this too. You've got blank line with ^$ but how do you negate that? A two-liner is %s/^/p/ - add p to the start of each line %s/^p$// - remove any lines that contain only p
Re: multi line regex's in vi ...
while you can specify that a substitution take place on many lines (1,3s/// for lines 1-3, .,$s/// for lines here to end of file, or %s/// for lines all) VI is based on EX which is a line editor. yah, hence my question :) there may be some advanced voodoo mumbo-jumbo that will allow VIM (or ELVIS, another enhanced VI) to munge the double \n\n the way you want it to... that's what i wanted to know. i didn't think so but vim has lots of fancy mumbo jumbo in it :) try man wml for example (apt-get install wml if you don't have it)... cool, i'll check it out, thanks. adam.
Re: multi line regex's in vi ...
There are several ways in VIM. You can specify ranges (lines, counts) or globally. :%s/x/y/ . See the :help for more info. -- ¶ One·should·only·use·the·ASCII·characterset·when·compos » ing·email·messages.
Re: multi line regex's in vi ...
while you can specify that a substitution take place on many lines (1,3s/// for lines 1-3, .,$s/// for lines here to end of file, or %s/// for lines all) VI is based on EX which is a line editor. there may be some advanced voodoo mumbo-jumbo that will allow VIM (or ELVIS, another enhanced VI) to munge the double \n\n the way you want it to... but there's probably a better tool. try man wml for example (apt-get install wml if you don't have it)... just one suggestion, there are plenty of others (including perl and/or xml)...