5

I have the following code in my init.el

(xclip-mode +1)
(setq
  x-select-enable-clipboard t
  x-select-enable-primary t
  x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING)
  x-stretch-cursor t)

In a regular terminal, copy and paste works seamlessly. However in tmux the kill-ring is not synchronized with my regular clipboard, and yank does not yank from the clipboard. How can I fix this?

  • Is your tmux copy buffer, synchronized with your clipboard? – Nsukami _ Jan 9 '15 at 1:21
  • Yes, but emacs does not modify the tmux copy buffer. In addition, the synchronization is done on a keybinding based method and is not general. – PythonNut Jan 9 '15 at 3:29
  • I'm not really sure to have clearly understood your problem, but I think, the best approach would be to not modify the tmux copy buffer from Emacs. Instead, you should only modify the clipboard, then tmux should be able to grab what's inside the clipboard. – Nsukami _ Jan 10 '15 at 1:34
2

You need to customize the .tmux.conf too in addition to the below customization in emacs.

With the below setup here are few scenarios of how copy-pasting can work between emacs and tmux:

  • Copy/cut from emacs and paste in shell command line in tmux: Do M-w or C-w in emacs and TMUX_PREFIX C-y in tmux.
  • Copy from tmux and paste in emacs: Do TMUX_PREFIX C-w in tmux and C-y in emacs.

emacs setup

(setq x-select-enable-clipboard t 
      x-select-enable-primary t)

tmux setup

# COPY & PASTE

# Copy tmux buffer to X clipboard
# run -b runs a shell command in background
# bind C-w run -b "tmux show-buffer | xclip -selection clipboard -i"
bind C-w run -b "tmux show-buffer | xclip -i"

# Paste from X clipboard into tmux; also replace newline characters with
# space characters when pasting
bind C-y run -b "exec </dev/null; xclip -o | awk 1 ORS=' ' | tmux load-buffer - ; tmux paste-buffer"
# Same as `C-y' binding except that the newline chars are not replaced with space
bind Y run -b "exec </dev/null; xclip -o | tmux load-buffer - ; tmux paste-buffer"

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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