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>
> <i>nsert and type <P>
> <esc>
> q - stop recording
>
> 999@a - 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
Reply to: