Search code examples
vim

Why does vim use consecutive register when repeating pasting register x with dot command?


If my registers look like this:

Type Name Content
  l  ""   xxxxx^J
  c  "0   0000
  l  "1   xxxxx^J
  l  "2   11111^J
  l  "3   2222^J
  l  "4   3333^J
  l  "5   4444^J
  l  "6   5555^J
  l  "7   6666^J
  l  "8   7777^J
  l  "9   8888^J
  c  "-   h
  c  "*   xxxxx
  c  ".   xxxxx
  c  ":   reg
  c  "%   temp
  c  "/   \vq

and then I do "1p as expected xxxxx is pasted. If I then use the dot .-command I would expect that register 1 would be pasted again - instead register 2 is pasted: 11111. If I repeat the dot-command it iterates pasting through all the registers.

I have cleared my .vimrc to be sure that I don't have any funny settings there. I doubt that this is not working as designed. Any idea why this is behaving like this?

I am using vim 9.0 on Mac.


Solution

  • Two paragraphs below :help ., you can find:

    If the last change included a specification of a numbered register, the
    register number will be incremented.  See |redo-register| for an example how
    to use this.
    

    And if you follow the "link" to :help redo-register, you have all the explanation you can hope for:

    If you want to get back more than one part of deleted text, you can use a
    special feature of the repeat command ".".  It will increase the number of the
    register used.  So if you first do '"1P', the following "." will result in a
    '"2P'.  Repeating this will result in all numbered registers being inserted.
    
    Example:    If you deleted text with 'dd....' it can be restored with
                '"1P....'.
    
    If you don't know in which register the deleted text is, you can use the
    :display command.  An alternative is to try the first register with '"1P', and
    if it is not what you want do 'u.'.  This will remove the contents of the
    first put, and repeat the put command for the second register.  Repeat the
    'u.' until you got what you want.