Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tmux and macOS Clipboard

Is there a reliable way to make tmux 2.5 to work with macOS clipboard?

After upgrading to 2.5 everything went downhill. I have tried every solution I have found and nothing works. Could anybody please provide me with a working sample of tmux.conf that will make it work?

I can copy from neovim inside tmux just fine. I can't copy the text using tmux itself.

Here is what I have in .tmux.conf:

setw -g mode-keys vi
bind-key -T copy-mode-vi 'v' begin-selection
bind-key -T copy-mode-vi 'y' copy-pipe-and-cancel "reattach-to-user-namespace pbcopy" \; display-message "copied to system clipboard"

These are the errors that appear every time the session is started:

.tmux.conf:95: unknown command: begin-selection                
.tmux.conf:96: unknown command: copy-pipe-and-cancel

I have tried the following:

set-window-option -g mode-keys vi
bind-key -Tcopy-mode-vi 'v' send -X begin-selection
bind-key -Tcopy-mode-vi 'y' send -X copy-pipe-and-cancel pbcopy

I have also tried:

bind-key -Tcopy-mode-vi 'y' send -X copy-pipe-and-cancel

Nothing.

like image 373
firedev Avatar asked Jul 22 '17 13:07

firedev


People also ask

How do I copy from Tmux to clipboard on Mac?

"Shift + v" will select the whole line. Now move to the other end of the selection. Tmux will highlight your selection in yellow. Then press y or return to copy it to the clipboard.

How do I copy from clipboard to Tmux?

If you use tmux's copy mode keyboard commands to select some text and then click Ctrl + c or y it'll copy it into the system clipboard. y is the key that tmux-yank uses for copying to the clipboard, the same as vim's “yank” key (which ironically doesn't use the system clipboard by default in vim).

How do I copy file content to clipboard Mac?

Use "pbcopy" to copy content of file to your clipboard. the command will copy all content from "file. txt" directly on your clipboard.


1 Answers

I made it work with tmux 2.6 like so:

Removed any references of reattach-to-user-namespace and now I have this in my .tmux.conf:

set-window-option -g mode-keys vi
bind-key -T copy-mode-vi v send -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy"
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "pbcopy"
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "pbcopy"
like image 98
firedev Avatar answered Sep 29 '22 19:09

firedev