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?
In the Terminal app on your Mac, do any of the following: Copy text in another app, and then in Terminal choose Edit > Paste. Drag selected text into a Terminal window from any macOS app that supports it.
Triple-click the Left Mouse Button on a line to select the whole line and copy it into the primary selection. Click the Middle Mouse Button to paste from the primary selection. Ctrl + Shift + c to copy the selection into the clipboard.
Copy Mode allows you to make selections using the keyboard. To enter or exit Copy Mode, select Edit > Copy Mode. You can also enter copy mode by pressing Shift+Arrow key immediately after making a selection with the mouse.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With