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"