It’s a secret for no one, I love VIM. But one of the most annoying moment is when you copy a line somewhere (yy) then you delete a line somewhere else (dd) and finally you want to paste the previously yanked line somewhere else. Well, we’ve all been there haven’t we?
Where is the problem?
The problem is that when you either yank or delete a line/char/multiple lines, vim copy what you’ve just done in a global register, and overrides the previous content.
One of the solution is to use “ (double quotes) to set your register before doing the overriding action.
Will copy your line in you register a
Will paste the content of the a register
But let’s be fair, we all make mistakes, and there are times when you forget to yank your stuff in a specific register, and this is where the problem occurs, because you usually end up in a serie of undo to retrieve your text back.
Yank Ring as a solution
While helping a friend today who is starting with Vim, it was pretty clear that the register wasn’t a good solution, and we found Yank Rink.
It’s a pretty cool solution that will allocate different registers to your copy/delete operation, so every time you copy/delete something, it’s won’t override the previous one.
You can then use Ctrl-P to swap between the allocated registers, making finding the right one a breeze.
Finally it offers you :YRShow and YRSearch to respectively show and search the content of you registers.
So if you’re stuck in a yank hell, I would definitively recommend looking at this plugin Yank Rink.