38

I don't understand the middle click paste.

Sometimes I highlight text, middle click in the window where I want it to go and it does what I want. Sometimes it doesn't.

For instance, when I highlight text in Firefox, then go and middle click into terminal vim, nothing happens.

What is going on?

Thank you!

Jorge Castro
  • 73,717
Fawkes5
  • 2,539

3 Answers3

25

Caused by separate X/DE clipboards; keep them synchronized with ClipIt

  • As ImaginaryRobots' answer explains there are two different clipboards: the X clipboard and the desktop environment/window manager clipboard (Gnome/Unity, KDE, etc.); depending on the selection method used (i.e. just highlighting, or an explicit Ctrl-C/right-click copy, etc.), the two clipboards may not be synchronized.

    • Thus, there are often issues when copying/pasting between GUI programs and the terminal.
  • The easiest solution if you have this problem is to use a tool that keeps both these separate clipboards in sync. I recommend ClipIt (sudo apt-get install clipit)

    • Start clipit (add to Startup Applications for convenience), and under Preferences, check both the Use Primary and Synchronize Clipboards options:

    enter image description here

ish
  • 141,990
22

There are actually 2 different kinds of copy & paste - there's the one provided by the underlying X11 graphics system, and there's the one provided by your window manager (Gnome, KDE, etc).

Highlighting text without clicking is enough to get it copied to the X11 buffer-space, and middle-clicking will paste out of that. If you use control-X or control-C, it will use the window-manager's buffer space as well (since you had to have highlighted it to use those keys), but only a control-V will get the text out of there - middle clicking won't.

To make things more confusing, window manager copy & paste will work with non-text items too, so even if your highlighting had gotten some text into both buffers, you might then have some files or complex data in the window-manager buffer instead and the two will be out of sync.

Some applications are smart enough to understand and use both, others aren't. Terminal windows are usually of the stupid variety when it comes to copy & paste. There are usually settings for each application to tell them how to fix the copy & paste mess, but getting them all set up correctly is a lot of work. Ubuntu gets most of them by default, I think.

The situation was historically much worse, and led to freedesktop defining standards around it:

http://standards.freedesktop.org/clipboards-spec/clipboards-latest.txt

-1

Okay so when you select the text, you must click on an empty area to deselect the text and then middle click wherever you want to paste it, if you don't deselect the highlighted area then it will NOT work.