I'd like to be able to paste the X selection using the keyboard.  Currently I have to use the middle mouse button to do this.I gather that faking a middle mouse button press is fairly easy to do, but such a solution would also require moving the mouse pointer to the location of the text caret.Is there a better way to do this?
Pasting X selection (not clipboard contents) with keyboard
xorg;keyboard shortcuts;copy paste
On some default linux setups, Shift+Insert will perform an X-selection-paste. As you noted, this is distinctly different from the X-clipboard-paste command, the binding for which often varies by application. If that doesn't work here are a couple other keys to try:Ctrl+VCtrl+Shift+VCtrl+Shift+InsertNo go? Your Desktop Environment or Window Manager probably doesn't have them configured, and it's complicated because even under the banner of one DE or WM each toolkit (e.g. GTK, Qt, Etc.) may well have different default bindings. Some programs (e.g. gvim) even have their own internal copy registers that are not necessarily synced to the graphical environment they run in. To top it off, even when a program does use the X-clipboard system, X has multiple systems to choose from. The two most basic are the selection buffer which always has whatever the last thing selected was (execpt when it doesn't) and the copy buffer which things usually need to be specifically copied into. To do an explicit copy into the latter system you can try any of these on for size:Ctrl+CShift+Ctrl+CCtrl+InsertIf none of that is just magically working for you, there are two ways you can go.There's an app for that! Use one of the various clipboard manager programs to handle this for you. The most popular seem to be Parcellite and Glippy, but you can check out other alternatives here. See also this question about advanced clipboard managersHack it yourself.So lets say you want to hack it.Short of writing your own code and tapping into the X api, the hacker tools for the job are a couple of little command line utilities that give you a window into the mind of X. Just a small window mind you, the whole view too scary.The first tool is xsel. This little jobber will spit out whatever is in X's selection buffer at any given time.Now you need to get that into your program. There are two options for this. One is xdotool which allows you to mimic sending events to the Xorg input system. You can use it's type method like xdotool type foo_bar to mimic typing 'foo_bar' at the cursor. Combined, you get something like this:$ xdotool type $(xsel)The other one is xvkbd which sends keyboard events from a lower subsystem. You can pipe keystrokes into it on STDIN. Combined with xsel, you get something like this:$ xsel | xvkbd -xsendevent -file -Great. Now for that keybinding to run this stuff. If you run Gnome-2, you can add a custom shortcut in System -> Preferences -> Keyboard shortcuts. If you use a different DE or WM this excersize is left up to the reader.The last note is that when binding commands to keyboard shortcuts it is often necessary to only have one command, not two commands connected with a pipe like we use above. You can accomplish this by invoking your piped command as a command string argumetn to a new shell like this:sh -c 'xsel | xvkbd -xsendevent -file -'sh -c 'xdotool type $(xsel)'