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

Problem with Visual selection on an empty line

Expand Messages
  • glts
    When a v Visual selection ends on an empty line it will also delete the newline and join the next line. Is there a way to avoid this? Here s an example text
    Message 1 of 5 , Apr 9, 2013
    • 0 Attachment
      When a "v" Visual selection ends on an empty line it will also delete
      the newline and join the next line. Is there a way to avoid this?

      Here's an example text with the cursor on b:

      abc
      d
      xyz

      Now pressing vj and then d results in:

      axyz

      I would not have expected line 3 joined to line 1 but I can see that
      it's because I also deleted the newline on line 2. Thus I can simply use
      h to exclude the newline. Same situation, pressing vjhd gives:

      a
      xyz

      But what if the line between abc and xyz is empty?

      abc

      xyz

      Now vjd will always result in:

      axyz

      But I don't like this, it goes against my intuition. Is there a way to
      tell Vim not to include the newline character in the Visual selection,
      so that I get the same result as with vjhd?

      Thanks.

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

      ---
      You received this message because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Ben Fritz
      ... Why are you including the empty line in your visual selection at all? There is nothing there to delete except the line itself. -- -- You received this
      Message 2 of 5 , Apr 9, 2013
      • 0 Attachment
        On Tuesday, April 9, 2013 6:26:58 AM UTC-5, glts wrote:
        >
        > But what if the line between abc and xyz is empty?
        >
        > abc
        >
        > xyz
        >
        > Now vjd will always result in:
        >
        > axyz
        >
        > But I don't like this, it goes against my intuition. Is there a way to
        > tell Vim not to include the newline character in the Visual selection,
        > so that I get the same result as with vjhd?
        >

        Why are you including the empty line in your visual selection at all? There is nothing there to delete except the line itself.

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

        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • Christian Brabandt
        Hi glts! ... regards, Christian -- Wenn uns das Böse als Böses Reue macht und nicht als Wirkung der Strafe: warum bereuen wir einen bösen Willen, einen
        Message 3 of 5 , Apr 9, 2013
        • 0 Attachment
          Hi glts!

          On Di, 09 Apr 2013, glts wrote:

          > When a "v" Visual selection ends on an empty line it will also delete
          > the newline and join the next line. Is there a way to avoid this?
          >
          > Here's an example text with the cursor on b:
          >
          > abc
          > d
          > xyz
          >
          > Now pressing vj and then d results in:
          >
          > axyz
          >
          > I would not have expected line 3 joined to line 1 but I can see that
          > it's because I also deleted the newline on line 2. Thus I can simply use
          > h to exclude the newline. Same situation, pressing vjhd gives:
          >
          > a
          > xyz
          >
          > But what if the line between abc and xyz is empty?
          >
          > abc
          >
          > xyz
          >
          > Now vjd will always result in:
          >
          > axyz
          >
          > But I don't like this, it goes against my intuition. Is there a way to
          > tell Vim not to include the newline character in the Visual selection,
          > so that I get the same result as with vjhd?

          :set selection=exclusive

          regards,
          Christian
          --
          Wenn uns das Böse als Böses Reue macht und nicht als Wirkung der
          Strafe: warum bereuen wir einen bösen Willen, einen bösen Entschluß,
          der nicht ausgeführt wurde, nicht ebensosehr als eine böse Handlung?
          -- Jean Paul

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

          ---
          You received this message because you are subscribed to the Google Groups "vim_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • glts
          ... I m sorry, I should have mentioned that this is just a simplified example. Sometimes I start a selection in the middle of a line and then extend it
          Message 4 of 5 , Apr 9, 2013
          • 0 Attachment
            On Tuesday, April 9, 2013 5:48:25 PM UTC+2, Ben Fritz wrote:
            > On Tuesday, April 9, 2013 6:26:58 AM UTC-5, glts wrote:
            > >
            > > But what if the line between abc and xyz is empty?
            > >
            > > abc
            > >
            > > xyz
            > >
            > > Now vjd will always result in:
            > >
            > > axyz
            > >
            > > But I don't like this, it goes against my intuition. Is there a way to
            > > tell Vim not to include the newline character in the Visual selection,
            > > so that I get the same result as with vjhd?
            > >
            >
            > Why are you including the empty line in your visual selection at all? There is nothing there to delete except the line itself.

            I'm sorry, I should have mentioned that this is just a simplified
            example.

            Sometimes I start a selection in the middle of a line and then extend it
            downwards. Sometimes the selection ends on an empty line or on a stretch
            of empty lines. I can see what I selected and then operate on it.

            It is in these circumstances that I expect a result like:

            a
            xyz

            I expect d to delete the highlighted line or lines so to speak. I don't
            expect it to delete the newline character even though that may be the
            correct behaviour strictly speaking.

            The procedure I'm using now is k$ and then d, but unfortunately that
            solution is not suitable for scripting. Also, I have to remember using
            it.

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

            ---
            You received this message because you are subscribed to the Google Groups "vim_use" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
            For more options, visit https://groups.google.com/groups/opt_out.
          • glts
            ... Yes. Unfortunately, I have to pass the selection to a plugin over which I have no control, so setting selection is out of question. I think I m just
            Message 5 of 5 , Apr 9, 2013
            • 0 Attachment
              On Tuesday, April 9, 2013 5:59:16 PM UTC+2, Christian Brabandt wrote:
              > :set selection=exclusive

              Yes. Unfortunately, I have to pass the selection to a plugin over which
              I have no control, so setting 'selection' is out of question.

              I think I'm just going to back up when getline(ln) =~ '^$' or something.

              Thanks.

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

              ---
              You received this message because you are subscribed to the Google Groups "vim_use" group.
              To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
              For more options, visit https://groups.google.com/groups/opt_out.
            Your message has been successfully submitted and would be delivered to recipients shortly.