How does Middle Click paste work?

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


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