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.
For example
<code>"ayy
</code>
Will copy your line in you register a
and
<code>"ap
</code>
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.