This is what I do:
- Go into visual mode
- Highlight some text
- Press y (or x)
- Go back into command mode
- Press p
About 2 times out of 5 Vim forgets the text and usually just pastes a newline. It’s very frustrating. Is this a bug? I can’t seem to reproduce it, it seems totally random.
When you run
p, it pastes from the default register. The contents of the default register are altered each time you do any of the following:yto yankd{motion}to deletexto delete a characterc{motion}to delete and enter insert modesto delete a character and enter insert modepwill overwrite the selected text with the default register, and overwrite the default register with the text that was selected (or in simpler terms, it swaps the default register and the selected text).With so many commands touching the default register, it is quite frequently the case that it doesn’t contain what you expect it to. For this reason, it’s good to get into the habit of always specifying a register when you delete or yank something that you intend to paste later.
Try this instead:
"ay(or"ax)"ap