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

how to undo a register insertion using i_CTRL-R?

Expand Messages
  • Maciej Kalisiak
    I love the ability of inserting a register content, directly in insert mode, using i_CTRL-R. However, this gets me into trouble from time to time. For
    Message 1 of 5 , Mar 29 8:55 AM
    • 0 Attachment
      I love the ability of inserting a register content, directly in insert mode, using i_CTRL-R. However, this gets me into trouble from time to time.

      For example, I might be on a roll, and without leaving insert mode, I enter a whole paragraph or three, which I want to finish with a contents of a register, which I insert using i_CRTL-R. Except, it turns out I did not get the right register (e.g., there was an intervening cut, so it's no longer "1 but rather "2 or "3). Instead of the expected word or phrase, I accidentally pasted a register which contained massive amount of text. Great, I'll just hit undo key in normal mode to undo it. But hold on! This also undoes the whole paragraph or three I typed in before the mistake.

      Gah, how do I undo just the register insertion?! Or do I have to train myself to leave insert mode before register pastes?

      --
      --
      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
      ... This problem, and it s prevention, is closely related to: http://vim.wikia.com/wiki/Recover_from_accidental_Ctrl-U To sum up, you should set up a mapping
      Message 2 of 5 , Mar 29 11:07 AM
      • 0 Attachment
        On Friday, March 29, 2013 10:55:09 AM UTC-5, Maciej Kalisiak wrote:
        > I love the ability of inserting a register content, directly in insert mode, using i_CTRL-R. However, this gets me into trouble from time to time.
        >
        > For example, I might be on a roll, and without leaving insert mode, I enter a whole paragraph or three, which I want to finish with a contents of a register, which I insert using i_CRTL-R. Except, it turns out I did not get the right register (e.g., there was an intervening cut, so it's no longer "1 but rather "2 or "3). Instead of the expected word or phrase, I accidentally pasted a register which contained massive amount of text. Great, I'll just hit undo key in normal mode to undo it. But hold on! This also undoes the whole paragraph or three I typed in before the mistake.
        >
        > Gah, how do I undo just the register insertion?! Or do I have to train myself to leave insert mode before register pastes?

        This problem, and it's prevention, is closely related to:

        http://vim.wikia.com/wiki/Recover_from_accidental_Ctrl-U

        To sum up, you should set up a mapping to break the current undo sequence before triggering the CTRL-R, like:

        inoremap <C-R> <C-G>u<C-R>

        --
        --
        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
        ... The problem with this solution, and the reason I don t use it, is because this will make it so you can no longer repeat the change with . in normal mode.
        Message 3 of 5 , Mar 29 11:09 AM
        • 0 Attachment
          On Friday, March 29, 2013 1:07:56 PM UTC-5, Ben Fritz wrote:
          > On Friday, March 29, 2013 10:55:09 AM UTC-5, Maciej Kalisiak wrote:
          > > I love the ability of inserting a register content, directly in insert mode, using i_CTRL-R. However, this gets me into trouble from time to time.
          > >
          > > For example, I might be on a roll, and without leaving insert mode, I enter a whole paragraph or three, which I want to finish with a contents of a register, which I insert using i_CRTL-R. Except, it turns out I did not get the right register (e.g., there was an intervening cut, so it's no longer "1 but rather "2 or "3). Instead of the expected word or phrase, I accidentally pasted a register which contained massive amount of text. Great, I'll just hit undo key in normal mode to undo it. But hold on! This also undoes the whole paragraph or three I typed in before the mistake.
          > >
          > > Gah, how do I undo just the register insertion?! Or do I have to train myself to leave insert mode before register pastes?
          >
          > This problem, and it's prevention, is closely related to:
          >
          > http://vim.wikia.com/wiki/Recover_from_accidental_Ctrl-U
          >
          > To sum up, you should set up a mapping to break the current undo sequence before triggering the CTRL-R, like:
          >
          > inoremap <C-R> <C-G>u<C-R>

          The problem with this solution, and the reason I don't use it, is because this will make it so you can no longer repeat the change with '.' in normal mode.

          --
          --
          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 Ben! ... Can you give an example? I just tried repeating using . and it seemed to work ok. Mit freundlichen Grüßen Christian -- Es ist viel leichter,
          Message 4 of 5 , Mar 29 12:15 PM
          • 0 Attachment
            Hi Ben!

            On Fr, 29 Mär 2013, Ben Fritz wrote:

            > On Friday, March 29, 2013 1:07:56 PM UTC-5, Ben Fritz wrote:
            > > On Friday, March 29, 2013 10:55:09 AM UTC-5, Maciej Kalisiak wrote:
            > > > I love the ability of inserting a register content, directly in insert mode, using i_CTRL-R. However, this gets me into trouble from time to time.
            > > >
            > > > For example, I might be on a roll, and without leaving insert mode, I enter a whole paragraph or three, which I want to finish with a contents of a register, which I insert using i_CRTL-R. Except, it turns out I did not get the right register (e.g., there was an intervening cut, so it's no longer "1 but rather "2 or "3). Instead of the expected word or phrase, I accidentally pasted a register which contained massive amount of text. Great, I'll just hit undo key in normal mode to undo it. But hold on! This also undoes the whole paragraph or three I typed in before the mistake.
            > > >
            > > > Gah, how do I undo just the register insertion?! Or do I have to train myself to leave insert mode before register pastes?
            > >
            > > This problem, and it's prevention, is closely related to:
            > >
            > > http://vim.wikia.com/wiki/Recover_from_accidental_Ctrl-U
            > >
            > > To sum up, you should set up a mapping to break the current undo sequence before triggering the CTRL-R, like:
            > >
            > > inoremap <C-R> <C-G>u<C-R>
            >
            > The problem with this solution, and the reason I don't use it, is because this will make it so you can no longer repeat the change with '.' in normal mode.

            Can you give an example? I just tried repeating using '.' and it seemed
            to work ok.

            Mit freundlichen Grüßen
            Christian
            --
            Es ist viel leichter, einen ersten Wunsch zu unterdrücken, als sich
            die Wünsche zu erfüllen, die der erste nach sich zieht.
            -- François de La Rochefoucauld

            --
            --
            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
            ... I just tested and you re right, it does work OK. But according to :help ins-special-special, it shouldn t work. The help says, Only the last change can be
            Message 5 of 5 , Mar 29 1:22 PM
            • 0 Attachment
              On Friday, March 29, 2013 2:15:19 PM UTC-5, Christian Brabandt wrote:
              > Hi Ben!
              >
              >
              >
              > On Fr, 29 M�r 2013, Ben Fritz wrote:
              > > >
              >
              > > > inoremap <C-R> <C-G>u<C-R>
              >
              > >
              >
              > > The problem with this solution, and the reason I don't use it, is because this will make it so you can no longer repeat the change with '.' in normal mode.
              >
              >
              >
              > Can you give an example? I just tried repeating using '.' and it seemed
              >
              > to work ok.
              >

              I just tested and you're right, it does work OK. But according to :help ins-special-special, it shouldn't work. The help says, "Only the last change can be redone and always behaves like an "i" command."

              Consider text "somevar" in register 'a'.

              The following keysequence will insert a line with text, "printf(somevar);":
              oprintf(<C-R>a);

              In this case, I expect the following two mappings to be equivalent:
              inoremap <C-R> <Left><Right><C-R>
              inoremap <C-R> <C-G>u<C-R>

              Without any mapping, pressing 'u' after the insertion will undo the entire insertion. With either mapping, pressing 'u' will only undo inserting "somevar);".

              Without any mapping, pressing '.' will repeat the entire insertion. I expect that with either mapping, pressing '.' will only repeat inserting "somevar);" which is not very helpful.

              But experimentation shows that the first mapping behaves in the expected unhelpful manner, but the second mapping behaves helpfully, with both "undo" and "repeat" working as intended.

              I'm not sure why this works, but I'm glad for it. I'll put that second mapping in my .vimrc now. Can we update the docs?

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