If I select text in my terminal (in my case urxvt) and then click with the middle mouse button into an emacs window (GTK), it pastes the selected text from terminal.

Since I don't want this behaviour for the middle mouse button I usually add this to my .emacs file:

(define-key global-map [mouse-2] nil)

However then I am not able to paste text from a terminal at all. So how can I fix this (for example that a selection from a terminal is inserted by C-y)?

This worked in my old box but since upgrading to ubuntu 13.10 and emacs24 it doesn't. So it must be possible, but I don't know how to.

2 Answers 2


From the Emacs manual, section 12.3.1 Using the Clipboard:

Prior to Emacs 24, the kill and yank commands used the primary selection, not the clipboard. If you prefer this behavior, change x-select-enable-clipboard to nil, x-select-enable-primary to t, and mouse-drag-copy-region to t. In this case, you can use the following commands to act explicitly on the clipboard: clipboard-kill-region kills the region and saves it to the clipboard; clipboard-kill-ring-save copies the region to the kill ring and saves it to the clipboard; and clipboard-yank yanks the contents of the clipboard at point.

The key setting you want is x-select-enable-primary to t. You can also use a mix of the settings described there, depending on exactly what behavior you like.


Both the variable x-select-enable-clipboard and function called x-cut-buffer-or-selection-value seem to be significant.

(setq x-select-enable-clipboard t)
(setq interprogram-paste-function 'x-cut-buffer-or-selection-value)

Read more from this Source : Integrate emacs copy paste with system copy paste

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .