This might be extraordinarily simple, but I am playing with Emacs (22.1.1) and I can't get it to paste text in the clipboard using Control-Y.
-
Using evil (simulating vim-like behaviour), I use this trick: `:r!xsel` or `:r!xsel -b` what reads output of command specified after exclamation mark. On MacOS you would probably use `pbaste`. – Jan Vlcinsky Jul 06 '15 at 13:55
8 Answers
Try using the M-x clipboard-yank
command. If you want to copy text to the clipboard you have to M-x clipboard-kill-region
.
This works on Linux and Windows, I guess on Mac it's the same.

- 6,707
- 6
- 32
- 45
-
3I actually tried this at work today on my Ubuntu 11.10 using the lastest emacs and it did not work. It says the kill ring is empty. I am using your first command. – n_x_l Apr 03 '12 at 12:12
-
1Brilliant! I am running emacs 24.3 on Ubuntu 12.04 and connecting via Windows 7 using XWin Server and this pulled the contents from my Windows clipboard into my emacs session. Thanks! – Matt Klein Oct 21 '13 at 16:57
-
1Confirming that this does work on a Mac -- using OS X 10.8.5 and Emacs 24.3. I did not test this with Aquamacs. – jdl Dec 19 '13 at 17:55
-
this works on debian, emacs 24.10. The accepted answer wont work here. – pr00thmatic Jan 09 '14 at 13:28
-
3The `clipboard-yank` broken at least in Emacs-25.0 — in the presence of `select-enable-clipboard` set to «nil» does not anymore works with clipboard. On the other hand I guess that could be a bugfix, cuz the docs clearly says, that the function may paste last killed text as well. But in fact I doesn't see a way now to disable clipboard contaminating, and yet be able to use it's content. – Hi-Angel Apr 18 '15 at 08:53
-
If you're using the in-built Emacs, then you're running Emacs in the terminal. The "clipboard" is a function of your windowing system. Emacs in terminal mode (-nw
) does not access any windowing system specific APIs. This is true of most command line tools designed to work in the terminal.
You need to upgrade your Emacs as others have suggested, and run in graphical mode. Using Emacs 24 on Mac OS X, the behaviour you want is the default.
If you want to do this in a terminal, then this hack will make the clipboard work.
(defun copy-from-osx ()
(shell-command-to-string "pbpaste"))
(defun paste-to-osx (text &optional push)
(let ((process-connection-type nil))
(let ((proc (start-process "pbcopy" "*Messages*" "pbcopy")))
(process-send-string proc text)
(process-send-eof proc))))
(setq interprogram-cut-function 'paste-to-osx)
(setq interprogram-paste-function 'copy-from-osx)
-
Perfect answer. One quick comment though: if I upgrade my Emacs and then use the -nw to run it in the terminal, will I be able to use the system clipboard? Or I need to use the hack if I want to work in the terminal regardless of the Emacs version? – n_x_l Apr 04 '12 at 12:17
-
1Terminal applications can't access the system clipboard. The hack isn't so bad though, I do use `pbcopy` in other contexts. – event_jr Apr 04 '12 at 12:41
-
I use Emacs 24.1 but can't paste to emacs from clipboard even if I use graphical mode. – newguy Sep 24 '12 at 13:13
-
2
-
1[Here](http://allkindsofrandomstuff.blogspot.de/2009/09/sharing-mac-clipboard-with-emacs.html) is the same or a similar link. – Frank Zalkow Nov 12 '13 at 17:44
-
The beginning of this answer is inaccurate: I access the system clipboard from Vim in the terminal all the time. There's no reason a terminal application can't interact with the system clipboard. `pbcopy` and `pbpaste` are, after all, processs running in the terminal themselves. – Peeja Jun 19 '15 at 14:59
-
@Peeja Your perception of what's running "in terminal" is not correct. You can launch an executable from the terminal that runs in your windowing system. You can launch "Finder" form a terminal, does that mean it's "running in terminal"? – event_jr Jun 19 '15 at 17:26
-
1No, that's not what I'm talking about at all. I run Vim within tmux, within iTerm. It uses my system clipboard as the `*` register. Any running executable can access that clipboard, if the authors have used the API for it. – Peeja Jun 19 '15 at 19:35
-
-
@event_jr: To get your copy-from-osx hack to work, I had to add (interactive) to the defun. I didn't need paste-to-osx -- command-C copies whatever I highlight. Also, it seems to me you've named the functions in reverse -- your copy-from-osx pastes into the emacs buffer while paste-to-osx copies text into the clipboard for a subsequent paste operation. – Tom Barron Nov 25 '16 at 15:00
-
Can I also apply it for Linux systems? How can I run emacs in `graphical mode`? @event_jr – alper Jun 14 '20 at 01:05
I usually use Shift+insert to paste into an emacs buffer, I don't know if your keyboard has those keys though.

- 1,661
- 11
- 15
-
6Yeah it does not. Although I am beginner, I am surprised to find this difficult to do. – n_x_l Apr 03 '12 at 00:35
-
try the yank command, just do M-x yank. To see the keychord that runs this command on your system you may run C-h w yank – quicoju Apr 03 '12 at 00:52
-
1
That's strange.
I use command-V, and it works every time.
When you focus on the terminal window, anything you paste through command-V becomes separate keystrokes sent into the terminal.
I use Mac OS X 10.5 (Leopard) and emacs 22.1.1.

- 11
- 1
-
It seems the user has already resolved his issue though, by updating his Emacs. Also, the user wasn't using command-V, but C-y (which is the default command for "yanking" in Emacs). – default Mar 08 '13 at 09:28
See http://blog.binchen.org/?p=589
Here is code:
(require 'simpleclip)
(defun copy-to-clipboard ()
(interactive)
(let ((thing (if (region-active-p)
(buffer-substring-no-properties (region-beginning) (region-end))
(thing-at-point 'symbol))))
(simpleclip-set-contents thing)
(message "thing => clipboard!")))
(defun paste-from-clipboard()
"Paste string clipboard"
(interactive)
(insert (simpleclip-get-contents)))
The code use simpleclip (https://github.com/rolandwalker/simpleclip)
Simpleclip requires you install some command line tool on Mac/Linux/Cygwin which . So even emacs without graphic support could also access clipboard.
This solution works on any version of Emacs, any OS. It also works when your remote ssh if the server enables X forward, the complete command is ssh -X -C -c blowfish-cbc,arcfour name@host.com
)

- 568
- 4
- 16
-
Isn't this answer restricted to X11, in which case it does not work with macOS-native versions of emacs? – Eric O. Lebigot Sep 26 '16 at 14:34
OS suse 12.2 - emacs default version 24.2-15.8.2 (x86_64) just ignored pasting from clipboard by ctrl-y Finally problem resolved by down grade to version 23.3-15.5.1 (x86_64)
I ended up using pbcopy.el. I was using Doom Emacs.
To install it, run
M-x package-install
- Press the return key
- provide
pbcopy.el
as the package to install - Press the return key
- inside your config file, add:
(require 'pbcopy)
(turn-on-pbcopy)
- restart emacs
I also had tried using clipetty and simpleclip which did not work for me.

- 2,468
- 1
- 21
- 34
On Windows
? I have M-ins
bound to h-insert-x-selection
, which I have defined as follows:
(defun h-insert-x-selection () (interactive)
(insert (x-selection 'CLIPBOARD)))
(global-set-key [(meta insert)] 'h-insert-x-selection)
On XEmacs
it is different, where I have
(global-set-key [(shift insert)] 'x-insert-selection)

- 8,336
- 12
- 54
- 94

- 28,432
- 15
- 72
- 133
-
Did I mention I was a beginner? :) So you would have to do a key mapping for a simple paste? – n_x_l Apr 03 '12 at 00:02
-
I needed key mapping on Windows. I don't know about Max OSX, but if `C-y` is not doing it for you this seems easiest. – Miserable Variable Apr 03 '12 at 00:24