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

Re: how to undo a register insertion using i_CTRL-R?

Expand Messages
  • 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 1 of 5 , Mar 29, 2013
    • 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);":

      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.