Search code examples
tmux

Tmux Copy/Paste in MacOS


I'm using Tmux (2.5) on MacOS (10.12.5). I'm attempting to setup copy/paste using pbcopy and pbpaste however I must have something wrong w/ my tmux.conf as my key bindings don't appear to be working.

Here's the relevant portion of my tmux.conf:

# Rebind prefix to b
bind B set -g prefix ^b
bind A set -g prefix ^a

# Setup 'v' to begin selection as in Vim
unbind -T copy-mode-vi v
bind-key -Tcopy-mode-vi 'v' send -X begin-selection

unbind -T copy-mode-vi y
bind-key -T copy-mode-vi 'y' send-keys -X copy-pipe-and-cancel pbcopy

# Setup mouse to copy selection on drag
bind-key -Tcopy-mode-vi MouseDragEnd1Pane send -X copy-pipe-and-cancel pbcopy

# Update default binding of `Enter` to also use copy-pipe-and-cancel
unbind -T copy-mode-vi Enter
bind-key -T copy-mode-vi Enter send -X copy-pipe-and-cancel pbcopy

# Bind ']' to use pbpaste
bind-key -T copy-mode-vi ] send -X "pbpaste | tmux load-buffer - && tmux paste-buffer"

Any idea on why these wouldn't be working or suggestions on how to debug what's happening?


Solution

  • Here is my config https://github.com/imomaliev/dotfiles/blob/master/tmux/osx.conf. I use 2.5 as well and works ok for me

    # Copy to global clipboard
    # for sierra use: brew install reattach-to-user-namespace --with-wrap-pbcopy-and-pbpaste
    bind-key -Tcopy-mode-vi Y send -X copy-pipe "pbcopy"
    bind-key P run "pbpaste | tmux load-buffer - && tmux paste-buffer"