Monday, June 4, 2012

Re: Repeat gq from : command line?

On Tuesday, June 5, 2012 8:34:47 AM UTC+12, howardb21 wrote:
> On Mon, 4 Jun 2012, John Little wrote:
> > while line(".") < line("$")
> > :/^[[:lower:][:punct:]]\{3,}/normal gq/^\u^M
> > endwhile
> >
> > This works, I think, if the last line matches /^\L/.
>
> Nope does not work

It worked in the test file I used... but it's not a good approach.

> When I set nowrapscan, the search hits bottom and gives the error
> message:
>
> Search hit bottom without finding /^[[:lower:][:punct:]]\{3,}/
>
> But I KNOW there are nots of lines in that file that start with 3 lower
> case letters. So I do not see the problem with the above regular
> expression.

The problem is not with the regex, it's with making assumptions about where the current line is while making changes to the file.
>
> > :.,$g/^[[:lower:][:punct:]]\{3,}/normal gq/^\L^M
>
> I tried that initially but will mark every single line starting with
> lower case letters, even severl consequtive lines, and then try the
> format.
It still does the job, though. I thought about that, but thought that if the gq reformatted some lines the temporary marks that gq uses would be deleted.

> I need it to mark BLOCK lines that starting with one that begins
> with a lower case letter, and ends with an upper case one.

Well, you could use a multi-line regex, and the decorate-manipulate-undecorate "design pattern":

%s/^[[:lower:][:punct:]]\{3}\_.\{-}\_^\u/%\r&
g/^%$/normal jgq/^\u^M
g/^%$/d

Note the non-greedy match. One could combine the :g steps.

Regards, John

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment