I have noticed that zsh has a lot of things I see in emacs. I can make a selection with ctrl+space and selecting a region. I can make copies just like in emacs while I stay inside zsh. In emacs I'm able to use my system clipboard (previously with some additional configuration needed but this works out of the box now in emacs). In zsh I can't seem to paste from my clipboard using C-y and copying from zsh to my system cliipboard has the same issue. Is there a way around this?

3 Answers
3

Zsh's has a built-in clipboard that doesn't communicate with other applications. Since it's very scriptable, you can make it communicate with a few lines in your ~/.zshrc. You'll need xclip or xsel. See Pasting from clipboard to vi-enabled zsh or bash shell for a proof-of-concept in vi mode. Here's the corresponding code for emacs mode (you'll probably want to do something similar to other kill-* widgets).

I had been wanting to integrate Zsh's cut buffer with the X clipboard. I tried the aforementioned http://stchaz.free.fr/mouse.zsh but I found I disliked having all my Zsh operations populate the clipboard. For instance, sometimes I would copy something in a browser, and then go to a shell and edit the command line and then paste. But often editing the command line - deleting a word, for instance - modifies the Zsh cut buffer. For better or worse, X just has a clipboard, not a kill ring, so when a Zsh editing operation overwrites the clipboard, the thing I wanted to paste is lost - I can't yank-pop it (C-y M-y) as I could do in Zsh or Emacs.

So what I did instead is create new special keybindings to interact with the X clipboard through zsh. Turns out "^Xw" and "^Xy" are unused in both Emacs and Zsh, so I can get a consistent interface by binding them in both applications. This way the normal editing operations, cutbuffer, and kill ring are left alone. If I want to copy something to the clipboard I set the region and do "^Xw" (or if I've already killed it and the region is inactive I can just do "^Xw" to copy the cut buffer). Pasting from the clipboard is done with "^Xy".