2

I know that question has been asked dozens of times now, but i have tried every possible suggestion i have found online - nothing worked.

I can't figure out how can I copy/paste from my Windows 10 to emacs(which is run through "Bash on Ubuntu on Windows"). If i copy text on my Windows i cant paste it to emacs by clicking right button of my mouse. I have tried pasting by using Shift+Insert, but it keeps toggling "overwrite mode" and not pasting anything. I have tried unbinding overwrite mode but i couldnt achieve it.

I have also tried simpleclip package and it shows me "Clipboard support not available" whenever I try running "M+x simpleclip-copy/paste/cut".

Can anyone please help me?

  • You are probably after the key binding C-y, which is the yank command to insert from the kill-ring in emacs. – theldoria Mar 3 '18 at 11:02
  • If you would like to have a more windows like key binding, you can try adding (cua-mode 1) to your init.el. – theldoria Mar 3 '18 at 11:04
  • I am aware of C-y, which is the 'yank' from emacs clipboard. But i want to paste from my Windows 10 OS clipboard. Killing and yank within emacs works fine. But i need to bind keyboard to paste from Windows 10 OS clipboard to emacs(replication mouse-2 click) – Ilja Leiko Mar 3 '18 at 11:22
  • You need something on the Windows side which serves the x-clipboard. I have some experience with the Cygwin XWin server and the XMing server which is more lightweight. Both servers have a bridge from the windows clipboard to the x-clipboard. For the XWin server you need the command line option -clipboard. You can switch on clipboard integration of XMing by some entry in the application menu (it is easy). If you manage to get clipboard support working in the X-server you get it for free in emacs (in my experience). – Tobias Mar 3 '18 at 11:51
  • ... Note, if you want to use the X-server you need export DISPLAY=:0.0 in wbash. From my experience do not waste time on the terminal version of emacs but aim for the X11 version. I don't have much experience with the terminal version but there are again and again problem reports with that version here on emacs.stackexchange.com. If the last two comments really pin-point your problem I re-write them as an answer. But, at first I will wait and see if it is really a solution. – Tobias Mar 3 '18 at 12:01
1

To answer your question, try this:

  • mouse to the title bar (to the right of the red Ubuntu logo)
  • right click, and you should see a menu appear
  • mouse over Edit, move to the right, click on Paste

If you find it's doing unexpected indenting, you may want to put emacs in fundamental-mode (esc x fundamental-mode). This is inconvenient, so if you expect to do this often, you should use an X server such as MobaXTerm or XMing, and before running emacs you need to set the environment variable DISPLAY=":0"

| improve this answer | |
1

This answer is adapted from a post on Reddit.

You can define your own wsl-copy and wsl-paste functions by putting the following in your Emacs init file (.emacs):

; wsl-copy
(defun wsl-copy (start end)
  (interactive "r")
  (shell-command-on-region start end "clip.exe")
  (deactivate-mark))

; wsl-paste
(defun wsl-paste ()
  (interactive)
  (let ((clipboard
     (shell-command-to-string "powershell.exe -command 'Get-Clipboard' 2> /dev/null")))
    (setq clipboard (replace-regexp-in-string "\r" "" clipboard)) ; Remove Windows ^M characters
    (setq clipboard (substring clipboard 0 -1)) ; Remove newline added by Powershell
    (insert clipboard)))

To bind them to C-c C-c and C-c C-v, respectively, add this:

; Bind wsl-copy to C-c C-v
(global-set-key
 (kbd "C-c C-c")
 'wsl-copy)

; Bind wsl-paste to C-c C-v
(global-set-key
 (kbd "C-c C-v")
 'wsl-paste)
| improve this answer | |
  • This looks very much like it should be added to GNU ELPA's xclip.el package. I thankfully don't use Windows so I can't do it myself, but if you're interested in helping me by testing my code, please contact me by email. – Stefan Jul 13 at 14:50
  • @Stefan, I can't find your email on your profile. I've added my email address temporarily to my profile so you can email me. I would be happy to test xclip.el on Windows. – Riggy Jul 25 at 23:25
  • It's monnier@iro.umontreal.ca – Stefan Jul 26 at 0:46

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.