It's been a few years since I officially grasped Linux's (well, X Windows') weird concept of copying and pasting, with its multiple discrete copy/paste methods: the highlight + middle click version, and "clipboard" Edit->Copy" + "Edit->Paste version.
But once in a blue moon, copying and pasting in X still surprises me. Try this:
- Open Firefox and a text editor. I'm trying with Vim.
- Highlight some text in Firefox.
- Middle-click paste it into the editor. The highlighted text is pasted, as expected.
- Close Firefox.
- Middle-click into the editor again.
Can you guess what happens at the end? If you said "Some random text from another application and/or nothing at all is pasted rather than the stuff from Firefox", you're right!
But today I read this article on jwz.org and finally understood how copy/paste works in X. Highlighting text doesn't copy anything, it just announces to the world "If any applications want to middle-click paste something, come ask me for it". So if you close the application you wanted to paste text from before you actually do the pasting, the application isn't around to give you the text you wanted any more, so you can't get it. The Edit->Copy / Edit->Paste version of copy/paste behaves the same way. You can't "Copy", close app, "Paste".
Note, this is different from how MS Windows works. When you copy some text in Windows it really copies to another location. You can close the app and still paste away. But Windows has a different (inconsistent) behavior when copy/pasting files in Explorer. There, it behaves like X in Linux: if right click a file and "Copy", it doesn't actually do anything with the data until you paste. If you right-click, "Copy", delete the file, "Paste", you don't get an error until you try to Paste.
In Vim in Linux, the
"* register lets you access the "primary selection" (highlight / middle click selection), and the
"+ register lets you access the clipboard.
In Vim in Windows,
"+ do the same thing, and use the clipboard.