12

As a very new Emacs user, I've been using Ctrl+w and Ctrl+y to cut/copy and paste between buffers in Emacs. Is there a way to do the same thing so that not just Emacs, but the entire system, can have access to what I am copying and pasting? Thanks.

P.S. I would like to do this in Linux (in a terminal emulator running under X) and Mac OS X (e.g. with Terminal).

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
hpy
  • 4,517
  • 8
  • 53
  • 73

4 Answers4

8

On Linux, you can use xclip.el (https://www.emacswiki.org/emacs/xclip.el) to link the kill-ring to the clipboard from Emacs running in terminal (without losing the multiple-kill and yank capability).

To install: M-x package-install RET xclip RET. To use, just add (xclip-mode 1) to your ~/.emacs.


This didn't exist on Mac, so I modified xclip.el to work with the OSX pbcopy and pbpaste utilities. The result, pbcopy.el, is available here: https://gist.github.com/1023272

alper
  • 449
  • 2
  • 8
  • 20
Daniel
  • 81
  • 1
  • 1
  • To install: `M-x package-install RET xclip RET`. To use, just add `(xclip-mode 1)` to your `~/.emacs` – alper Jun 14 '20 at 01:23
5

When emacs is running under X, there are a number of ways to implement this (if I understand you correctly). If you have a recent version of emacs, I think the following lines in .emacs creates the most intuitive behavior:

(global-set-key "\C-w" 'clipboard-kill-region)
(global-set-key "\M-w" 'clipboard-kill-ring-save)
(global-set-key "\C-y" 'clipboard-yank)

As always, the poorly organized but informative EmacsWiki has information on this issue.

However, when you are running in a terminal these settings (and the others mentioned so far) won't help you since the terminal is sitting between emacs and X. How to copy text from the terminal will usually be terminal dependent.

Steven D
  • 45,310
  • 13
  • 119
  • 114
  • Thanks! Is what I am looking for, but when I tried it in Mac OS X Terminal running Emacs, the text that gets C-w in Emacs does not appear "pastable" in other Mac OS X applications. Is there more I should do? Thanks! – hpy Jan 29 '11 at 20:48
  • Unfortunately, when you are running emacs from the terminal, none of the solutions presented here will do much for you as far as I know. – Steven D Jan 30 '11 at 20:44
  • I tried all `clipboard-*` but seems like it did not able to paste the copied text from emacs (on a remote machine) to remote machine's shell – alper Jul 15 '20 at 13:03
3

You must be talking about X clipboard, so put this line into your .emacs file:

(custom-set-variables '(x-select-enable-clipboard t))
alex
  • 7,093
  • 6
  • 28
  • 30
1

In CarbonEmacs (a native look-n-feel build for Mac OS X) copy and paste between command-keys in native apps, middle-click in X and C-[w,y] in emacs just work.

  • Coming in late to say: "Maybe". I'm seeing unix newlines translated to lone carriage-returns, when copying/cutting in Emacs and looking at the result in the OS-X clipboard. Question and more details at http://superuser.com/questions/293656 – JRobert Jun 07 '11 at 12:36