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).

  • 1
    You should probably say if you are you running emacs in a terminal, in X, or some other way (say, CarbonEmacs on a mac), as it may make a difference. – dmckee Jan 29 '11 at 16:18
  • I am running Emacs in a X terminal, either in xterm in Linux, or Terminal in Mac OS X. Will update the question. – hpy Jan 29 '11 at 16:32

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

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


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

(custom-set-variables '(x-select-enable-clipboard t))

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.

  • 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

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 superuser.com/questions/293656 – JRobert Jun 7 '11 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.