Emacs has its own terminology for these concepts:
| Common Name | Common Key | Emacs Name | Emacs Key |
| Cut | C-x | Kill | C-w |
| Copy | C-c | Kill-ring-save | M-w |
| Paste | C-v | Yank | C-y |
| — | — | Yank next | M-y |
If you do not care for the DefaultKillingAndYanking key bindings, then consider these alternatives:
C-<ins>, C-<del>, and S-<ins>.C-x, C-c and C-v to copy and pasteDEL deletes the region; just typing replaces it.C-w and M-w act on the current line when TransientMarkMode is not activeX 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:
x-select-enable-primary - default nil; set this to t if you want the Emacs commands C-w and C-y to use the primary selection.x-select-enable-clipboard - default t; set this to nil if you want the Emacs commands C-w and C-y to 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:
(delete-selection-mode)
(setq interprogram-cut-function 'own-clipboard) (setq interprogram-paste-function 'get-clipboard)
You can use https://github.com/rolandwalker/simpleclip which ALWAYS works.
More specifically, for copy&paste, there are only two commands:
simpleclip-get-contents simpleclip-set-contents
Read clipboard history from clipboard managers (Parcellite, ClipIt at Linux and Flycut at Mac). https://github.com/redguardtoo/cliphist
If it’s getting to be a bit of a hassle, use https://github.com/thomp/datclip to simply show the primary, secondary, and clipboard selections in the datclip buffer.