1. VIM pain resolved: yank buffer overwritten after changing and pasting

    Often I yank a line, change something in the area I’d like to paste into, and then realize that my changes and deletes overwrote what was yanked. Yanking into a special register takes longer and is rather annoying, but there’s a workaround:

    From the VIM help, we know about the unnamed register:

    Vim fills this register with text deleted with the “d”, “c”, “s”, “x” commands or copied with the yank “y” command, regardless of whether or not a specific register was used (e.g.  ”xdd).

    So, the unnamed register contains whatever was yanked, changed or deleted most recently, and its contents get pasted when we hit “p”. That explains what happens but does nothing to solve the problem. Luckily, 

    Numbered register 0 contains the text from the most recent yank command, unless the command specified another register with [“x].

    That means a simple "0p in normal mode will paste what was yanked regardless of any deletes that took place after yanking. Not obvious but glad it’s there!

    8 months ago  /  24 notes  /  Comments

    1. layzie313 reblogged this from imissmyjuno
    2. imissmyjuno posted this
  2. blog comments powered by Disqus