8

How can i yank to/from windows clipboard when using:

  • Windows 7 (x64)
  • GNU Emacs 24.4.1 (x64)
  • Evil 1.0.9
  • and having (setq x-select-enable-clipboard nil) in my .emacs? (I put this line there because i didn't want vim changes (x, d, etc) to clobber my os clipboard.

I tried "+p, "*p, "+y, "*y, CTRL+Y but it doesn't work. When i run :registers it doesn't even show + or * registers.

To clarify: I want Emacs to behave like Vim when copying/yanking to/from different registers, without clobbering os clipboard with every text changing command. In particular:

  • yy - should NOT yank text to os clipboard (only to 0 register)
  • "+yy - should yank text to os clipboard
  • dd - should NOT clobber os clipboard
  • cw - shold NOT clobber os clipboard
  • etc.
5

I disabled the clipboard integration with:

(setq x-select-enable-clipboard nil)

Then you should still be able to copy and paste using the + register of evil. If you still want to integrate with the clipboard without evil, you could use this function to paste:

(defun paste-from-clipboard ()
  (interactive)
  (setq x-select-enable-clipboard t)
  (yank)
  (setq x-select-enable-clipboard nil))

and this one for copyping:

(defun copy-to-clipboard()
  (interactive)
  (setq x-select-enable-clipboard t)
  (kill-ring-save (region-beginning) (region-end))
  (setq x-select-enable-clipboard nil))

Then bind copy-to-clipboard to M-w and paste-from-clipboard to C-y, or other keybinding of your choice.

Edit: I'm running Archlinux. Can't say if this'll work on Windows.

  • Under Linux Mint the (setq x-select-enable-clipboard nil) is enough too because there are + and * registers to work with os clipboard, not under windows unfortunately. – Kossak Jun 26 '15 at 17:37
  • I tried your custom function (in windows) with evil plugin and (setq x-select-enable-clipboard nil): The yanking FROM os clipboard works as it should, but i can't yank the selection TO os clipboard (with bindings (define-key evil-normal-state-map (kbd "C-y") 'paste-from-clipboard) and (define-key evil-visual-state-map (kbd "C-y") 'paste-from-clipboard) – Kossak Jun 26 '15 at 17:39
  • I'm not sure if I get what you mean, paste-from-clipboard will only paste from clipboard. You'll need another function to copy to clipboard. I edited the question to added a copy-to-clipboard function. Please try if it works – Jesse Jun 26 '15 at 18:30
  • I wrongly thought the yank function copies to and from os clipboard (based on the presence of visual selection). Your other function does what i want, thank you. – Kossak Jun 27 '15 at 8:20
2

https://github.com/rolandwalker/simpleclip

it cover ALL the use cases on Mac/Linux/Windows/Cygwin.

More specifically, for copy&paste, there are only two commands:

simpleclip-get-contents
simpleclip-set-contents

Feel free to assign short keys.

  • This is wonderful, it simplifies interaction with the clipboard drastically. – loevborg Jan 3 '16 at 11:11

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.