7

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?

3 Answers 3

8

Here is how I do it using reattach-to-user-namespace.

set-window-option -g mode-keys vi
set -g default-command "reattach-to-user-namespace -l ${SHELL}"

bind-key -T copy-mode-vi 'v' send-keys -X begin-selection 
bind-key -T copy-mode-vi 'y' send-keys -X copy-pipe-and-cancel 'reattach-to-user-namespace pbcopy'
bind-key p paste-buffer

My blog post explains this in more detail.

0
4

Using Mojave with Terminal and tmux version 2.9a (installed via Homebrew). Installed reattach-to-user-namespace (also Homebrew).

This is my config:

unbind -T copy-mode-vi             MouseDragEnd1Pane                                         # Don't copy on mouse release
bind   -T copy-mode-vi v   send -X begin-selection                                           # Selection keybind
bind   -T copy-mode-vi C-v send -X rectangle-toggle                                          # Toggle selection mode
bind   -T copy-mode-vi y   send -X copy-pipe "reattach-to-user-namespace pbcopy" \; send -X clear-selection # Copy to clipboard

bind-key -T copy-mode-vi MouseDragEnd1Pane send -X copy-pipe "reattach-to-user-namespace pbcopy" \; send -X clear-selection

bind   -T copy-mode-vi y   send -X copy-pipe "reattach-to-user-namespace pbcopy" \; send -X clear-selection # Copy to clipboard

bind-key -T copy-mode MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"

This allows for vim-like copy (line selection and visual selection with v and ctrl+v) with mouse and keyboard

1

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"
2
  • Does "for sierra" mean that you don't need brew install before Sierra or after Sierra? Commented Apr 6 at 0:27
  • Hi, I think it was because it was required for Sierra, but worked on previous version. AFAIK it is needed for all later versions. Commented Apr 8 at 9:45

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