Keyboard shortcut for pasting the primary selection

Sending virtual keypresses doesn't work for me (see comments), but that answer inspired me to look for similar solutions. Sending a "text" event with xvkbd ignores the current state of your physical keyboard:

sh -c 'xsel | xvkbd -xsendevent -file - 2>/dev/null'

xvkbd -text uses a few backslash sequences, so rather than dance with escaping, -file works. Add -delay 0 to enter the text without delay between the “keystrokes”. xvkbd also outputs some warning text about modifiers, but it appears to be irrelevant to this use (but I didn't want to see it in ~/.xsession-errors).

I bound this to a shortcut using System > Preferences > Keyboard Shortcuts.

Note that you need to have xsel and xvkbd packages installed:

sudo apt-get install xsel xvkbd

I was looking for an answer for this very same question, and I found this answer that says that Shift+Insert is working to paste the primary selection. I works for me. Simpler.


You can get this with the combined use of the programs xdotool (click to install) and xsel (click to install).

xdotool can simulate typing into a window; xsel outputs the contents of the PRIMARY selection (by default); the following shell one liner will do the trick:

 xdotool type `xsel`

To bind this to any key using the System->Preferences->Keyboard shortcuts menu item it is necessary to wrap it in a shell invocation:

 sh -c 'xdotool type --clearmodifiers -- "`xsel`"'

Typing in xdotool will not work with some programs; see the notes in the xdotool documentation.