Loading ...
Sorry, an error occurred while loading the content.

Re: Repeat gq from : command line?

Expand Messages
  • howard Schwartz
    ... That is correct, my typing error. But there is still something wrong with this expression. For instance, when I do simple search with this expression like
    Message 1 of 8 , Jun 4, 2012
    • 0 Attachment
      On Sun, 3 Jun 2012, Tim Chase wrote:

      > 1) the 2nd "/" ends the search, but it looks like you have a "repeat
      > 3+ times" token outside that. I suspect you want
      >
      > :/^[[:lower:][:punct:]]\{3,}/ norm...

      That is correct, my typing error. But there is still something wrong
      with this expression. For instance, when I do simple search with this
      expression like this:

      /^[[:lower:][:punct:]]\{3,}/

      Vim selects lines that begin with a Capitol letter like these:

      Administration: $108
      Graphic Science
      SOURCE:NATIONALSCIENCEFOUNDATION
      Graphic by Arno Ghelfi
      Politicians argue over the federal budget
      every time Congress reconvenes in Janu-
      ary. But the money that the government

      The search should only locate lines that start with at least 3 lower case
      letters or punctuation. I do not understand how vim highlights lines
      that start with words like SOURCE or Politician. I seem to get what I
      want if I use something like /^\l and then a character class with \{3,}.
      It is as if \{3,} works differently with character classes than
      it does following simple atoms like \l.

      > 2) the space after "gq" seems particularly suspect. At a minimum, I
      > think you mean to write
      >
      > normal gq/^\L^M

      Does not seem to matter, and does not work eithe way when I try it.
      >
      >
      > The infinite looping is likely a result of not moving the cursor
      > combined with not modifying the line as you intend.

      Perhaps correct, if the command does not work, the cursor will not move
      and the while loop will go on forever. The reason I do not use a g or
      global command, is vim would mark each line and try the formating. I
      want it to mark one range of lines, do the gq command, move the cursor
      to the end of the filtered lines, and then repeat the sequence till the
      end of file.

      --
      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
    • howard Schwartz
      ... True, the last lines may not get selected by my pattern. So that is a necessary improvement. Also L matches anything that s not a lowercase character,
      Message 2 of 8 , Jun 4, 2012
      • 0 Attachment
        On Mon, 4 Jun 2012, John Little wrote:

        > while line(".") < line("$")
        >
        > but there's no guarantee that the cursor should ever move to the last line.

        True, the last lines may not get selected by my pattern. So that is a
        necessary improvement.

        Also \L matches anything that's not a lowercase character, including
        whitespace and punctuation.

        Correct again. I was fooled by an analogy - figuring if \l is lower case
        \L would be upper case. What I really want is /^\u

        > Assuming you meant
        >
        > 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, even when I put a capitol letter on the last line. I
        get the infinite regress, I get lines selected that start with a capitol
        letter, and when I interrupt the script, it seemed to get stuck on line
        2. In some the format command seems not be working.

        > Anyway, I bet you've got wrapscan set, so that the search wraps round
        > the beginning of the file, and so never fails, stopping the loop.

        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.

        > :.,$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. 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. Global will
        not do that. In fact, if there were a way to highlight to select
        multiple blocks like this in visual and select mode, and then do a gq on
        each block -- that would be perfect.

        --
        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
      • howard Schwartz
        ... That does just what I want, running fmt for block after block. But on the long files I am working with this takes forever to complete. I guess each block
        Message 3 of 8 , Jun 4, 2012
        • 0 Attachment
          Actually, a brute force solution is to is something like this:

          :g/^[[:lower:][:punct:]]/,/\u/!fmt

          That does just what I want, running fmt for block after block. But on the long
          files I am working with this takes forever to complete. I guess each block (in
          windows) gets sent to a temp file run through fmt and put back in vim.

          I believed that using the gq internal command would be much faster, since the
          whole text is already in a buffer. I just cant get it to work.


          --
          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
        • John Beckett
          ... That s because you have ignorecase set (check with :set ic? including the question mark). The best fix is to include C in the search pattern. It can go
          Message 4 of 8 , Jun 4, 2012
          • 0 Attachment
            howard Schwartz wrote:
            > That is correct, my typing error. But there is still
            > something wrong with this expression. For instance, when I do
            > simple search with this expression like this:
            >
            > /^[[:lower:][:punct:]]\{3,}/
            >
            > Vim selects lines that begin with a Capitol letter like these:

            That's because you have 'ignorecase' set (check with :set ic?
            including the question mark).

            The best fix is to include \C in the search pattern. It can go
            anywhere, for example just before the final slash at the end.

            > I want it to mark one range of lines, do the gq command, move
            > the cursor to the end of the filtered lines, and then repeat
            > the sequence till the end of file.

            I have not followed this thread, but :g// works like this:
            First, Vim notes all lines where a hit occurs, then, Vim returns
            to the beginning and performs the operation on the first hit,
            then the next, etc. That is, it will not move to the end of the
            filtered lines.

            I see a couple more messages about the issue. If it's not
            resolved soon, please reply to this with a brief statement of
            what you last tried (don't rehash the history), and what you
            would like it do.

            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
          • John Little
            ... It worked in the test file I used... but it s not a good approach. ... The problem is not with the regex, it s with making assumptions about where the
            Message 5 of 8 , Jun 4, 2012
            • 0 Attachment
              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
            Your message has been successfully submitted and would be delivered to recipients shortly.