Question

So I was writing along in Vim in Ubuntu, I did a :wq, then went back into Vim. I copied a portion of the text that I needed, then deleted that portion, :wq'd, then went back into Vim and accidentally copied another part. I need the portion that I copied at first. I can't just press u because I already got out of Vim and back in, so my undos don't go back to the previous session.

Is there any way to recover the first copied portion? Maybe some kind of recovery in Vim or see previous copies in Ubuntu?

Any help would be life-saving, and I would appreciate it a lot, thank you.

Was it helpful?

Solution

If the yanked text is not too big, you should take a look at the output of :reg. What you yanked is probably in register 1 or 2.

Registers are saved between sessions but there's a hard limit on the size of their content. You can see that limit on your system with :set viminfo?: the default value should include <50 and s10 meaning that the content of registers is saved if they consist of less than 50 lines and/or weight under 10 Kb.

If you yanked a couple of reasonably lengthy lines, you should be fine.

See :h 'viminfo' if you want to change these value.

OTHER TIPS

My answer will not help you in this case, but for the future, you can enable a persistent undofile from session to session.

To achieve that, you'll need to set the undofile option.

See :help persistent-undo

It will allow you to undo even after closing and reopening a file.

That option is only available since Vim 7.3

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top