ChrisJohnsen / tmux-MacOSX-pasteboard

Notes and workarounds for accessing the Mac OS X pasteboard in tmux sessions. Note: The pu branch (“Proposed Updates”) may be rewound without notice.
BSD 2-Clause "Simplified" License
2.38k stars 84 forks source link

Trouble using this when using emacs bindings and running emacs from within tmux #55

Open apolishch opened 7 years ago

apolishch commented 7 years ago

I am attempting to run both emacs and tmux and am having a real hard time getting copy/paste (kill/yank) to work right:

the relevant sections of my tmux config:

set-option -g mouse on
set-option -g default-command "reattach-to-user-namespace -l bash"
setw -g mode-keys emacs
bind-key -n -t emacs-copy M-w copy-pipe "reattach-to-user-namespace pbcopy"
bind-key -n C-y run "xclip -o | tmux load-buffer - ; tmux paste-buffer"

And of my emacs config:

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

This has the following effects:

1) I can copy and paste in my tmux with emacs buttons (M-w, C-y)

2) Whenever I attempt to select a region in my emacs (with C-Space for example), it also selects my line number from linum-mode

3) I can copy things that I select with my mouse inside emacs into my system clipboard AND the kill ring( e.g. selecting text with my mouse and hitting M-w causes me to be able to past in my browser/other applications with Command+V (I'm on a Mac) AND in emacs/tmux with C-y)

4) Selecting a region (with problem 2 baked in to boot) with C-Space and using either C-w or M-w, or just killing with C-k does not result in pastable result, either in the kill ring, or on the system clipboard.

Is there any way to fix problems 2/4 without getting rid of desirable properties 1/3?

Thanks so much!

ChrisJohnsen commented 7 years ago

For your 2), it sounds like you are making a tmux copy-mode selection; copy-mode will select anything that is on the screen, which includes the line numbers drawn by linum-mode in Emacs. I am not sure why C-Space would start tmux copy-mode though (unless you have a non-prefix tmux binding for C-Space).

For your 4), if you are in tmux copy-mode (as your point 2 indicates), then your C-w, M-w, and C-k would be processed by your emacs-copy bindings in tmux, not Emacs; the selection would go to a new tmux buffer, not the Emacs kill ring or the system pasteboard (except for M-w, since you rebound that to use pbcopy?). With the default bindings you can paste a tmux buffer with Prefix ].