Emacs has its own terminology for these concepts:
|Common Name||Common Key||Emacs Name||Emacs Key|
C-vto copy and paste
DELdeletes the region; just typing replaces it.
M-wact on the current line when TransientMarkMode is not active
X copy and paste support has historically been a mess. This is relevant, as Emacs supports the various aspects of this mess.
Important for this discussion is the understanding that X generally distinguishes between two types of selection, the PRIMARY and the CLIPBOARD. Every time you select a piece of text with the mouse, the selected text is set as the PRIMARY selection. Using the copy function will place the selected text into the CLIPBOARD. Pasting using the middle mouse button will insert the PRIMARY selection, pasting using the paste function will insert the CLIPBOARD.
With this out of the way, starting with Emacs 24.1, GNU Emacs should already do the right thing here. If you dislike this behavior, there are two options you can customize:
nil; set this to
tif you want the Emacs commands
C-yto use the primary selection.
t; set this to
nilif you want the Emacs commands
C-yto use the clipboard selection.
Yes, you can have Emacs use both at the same time.
This does not affect pasting using the middle mouse button. By default, this uses
mouse-yank-primary, which will only look at the primary selection. If you want the middle mouse button to insert the clipboard instead, use the following:
(global-set-key (kbd "<mouse-2>") 'x-clipboard-yank)
Finally, in other applications, pasting usually replaces the selected text with the contents of the clipboard. To enable this behavior in Emacs, use DeleteSelectionMode with the following:
(setq interprogram-cut-function 'own-clipboard) (setq interprogram-paste-function 'get-clipboard)