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

executing SHFT J on certain lines of a visual selection

Expand Messages
  • meino.cramer@gmx.de
    Hi, I want to apply SHFT-J (join lines) on those lines starting with a number which are followed by a line not starting with a number. Example: This lines:
    Message 1 of 6 , Oct 3, 2011
    • 0 Attachment
      Hi,

      I want to apply SHFT-J (join lines) on those lines starting with a number
      which are followed by a line not starting with a number.

      Example:

      This lines:

      3003 blurb foo gnats
      alice bob
      3409 netrino boson lightspeed
      3500 icecrean I scream

      will become

      3003 blurb foo gnats alice bob
      3409 netrino boson lightspeed
      3500 icecrean I scream


      I tried

      :/^[0-9/normal J

      but this joins all lines even when followed by a line starting with a
      number

      How can I acchieve this trick?

      Thank you very much in advance for any help ! :)

      Best regards,
      mcc

      --
      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
    • Taylor Hedberg
      ... See `:help :global` and `:help :join`. -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are
      Message 2 of 6 , Oct 3, 2011
      • 0 Attachment
        Try this:

        :g/^\d.*\n[^0-9]/j

        See `:help :global` and `:help :join`.

        --
        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
      • Tim Chase
        ... I d almost be tempted to do ... in case you have more than one line wrapped such as 1234 alpha beta gamma delta frog toad camel muskmelon The change means
        Message 3 of 6 , Oct 3, 2011
        • 0 Attachment
          On 10/03/11 11:17, Taylor Hedberg wrote:
          > Try this:
          >
          > :g/^\d.*\n[^0-9]/j
          >
          > See `:help :global` and `:help :join`.

          I'd almost be tempted to do

          :v/^\d/-j

          in case you have more than one line wrapped such as

          1234 alpha beta
          gamma delta
          frog toad
          camel muskmelon

          The change means "on lines that don't match my
          intended-start-of-line, join it with the previous line".

          -tim


          --
          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
        • meino.cramer@gmx.de
          ... Hi Taylor, hi Tim, thank you for your replies! :) Both commands do nothing here...what did I wrong? Best regards, mcc -- You received this message from the
          Message 4 of 6 , Oct 3, 2011
          • 0 Attachment
            Tim Chase <vim@...> [11-10-03 18:56]:
            > On 10/03/11 11:17, Taylor Hedberg wrote:
            > >Try this:
            > >
            > > :g/^\d.*\n[^0-9]/j
            > >
            > >See `:help :global` and `:help :join`.
            >
            > I'd almost be tempted to do
            >
            > :v/^\d/-j
            >
            > in case you have more than one line wrapped such as
            >
            > 1234 alpha beta
            > gamma delta
            > frog toad
            > camel muskmelon
            >
            > The change means "on lines that don't match my intended-start-of-line,
            > join it with the previous line".
            >
            > -tim
            >
            >
            > --
            > 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
            >

            Hi Taylor, hi Tim,

            thank you for your replies! :)

            Both commands do nothing here...what did I wrong?

            Best regards,
            mcc

            --
            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
          • Taylor Hedberg
            ... I really don t know. I tried both on the example text you provided and they worked for me. Do you have a command line mapping or abbreviation that could be
            Message 5 of 6 , Oct 3, 2011
            • 0 Attachment
              meino.cramer@..., Mon 2011-10-03 @ 19:17:20+0200:
              > Both commands do nothing here...what did I wrong?

              I really don't know. I tried both on the example text you provided and
              they worked for me.

              Do you have a command line mapping or abbreviation that could be
              interfering with the command (shot in the dark, I know).

              --
              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
            • Tim Chase
              ... Does your data look like the sample data you provided? :) Are you seeing visual artifacts of having wrap set and the lines in question don t really have
              Message 6 of 6 , Oct 3, 2011
              • 0 Attachment
                On 10/03/11 12:17, meino.cramer@... wrote:
                > Hi Taylor, hi Tim,
                >
                > Both commands do nothing here...what did I wrong?

                Does your data look like the sample data you provided? :)

                Are you seeing visual artifacts of having 'wrap' set and the
                lines in question don't really have newlines? When you say they
                do nothing, do you mean "nothing at all", or do you get an E486:
                "Pattern not found" or a "Pattern found on every line" response?

                -tim


                --
                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.