Skip to content

tmux.conf

G. Bai edited this page Aug 8, 2021 · 6 revisions

copy mode

^b [: enter copy mode

This one is good: tmux in practice: integration with the system clipboard

Everything you need to know about Tmux copy paste

Everything you need to know about Tmux copy paste - Ubuntu

default mode

^space: start selection

alt + w: copy to buffer

In macOS, press option + w to copy to buffer

vi mode

add this in ~/.tmux.conf, to use vi mode for working with the buffer:

setw -g mode-keys vi

space: start selection

enter: copy to buffer

tmux 2.4+ made a backwards incompatible change renaming vi-copy to copy-mode-vi.

Read this https://gist.github.com/brendanhay/1769870

copy over SSH

macOS

See https://gist.github.com/brendanhay/1769870#gistcomment-2334245

# tmux 2.6 doesn't need the 'reattach-to-user-namespace' gymnastics
setw    -g  mode-keys    vi
bind-key -T edit-mode-vi Up                send-keys -X history-up
bind-key -T edit-mode-vi Down              send-keys -X history-down
bind-key -T copy-mode-vi v                 send      -X begin-selection
bind-key -T copy-mode-vi [                 send-keys -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"
bind-key -T copy-mode-vi ]                 send-keys -X copy-selection

For older tmux versions, to copy in macOS you may need reattach-to-user-namespace by Chris Johnsen.

Linux

Install xclip using system package manager if not installed already.

bind -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xclip -i -f -selection primary | xclip -i -selection clipboard"

According to https://wiki.archlinux.org/index.php/Tmux#X_clipboard_integration:

Nevertheless, it is neater to use xsel because xclip does not close STDOUT after it has read from the tmux buffer. As such, tmux does not know that the copy task has completed, and continues to wait for xclip to terminate, thereby rendering tmux unresponsive. A workaround is to redirect STDOUT to /dev/null:

# Vim style
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -i -sel clip > /dev/null"
bind-key p run "xclip -o -sel clip | tmux load-buffer - ; tmux paste-buffer"

Helper scripts

  • update_display_tmuxline.sh updates environment variable $DISPLAY and tmuxline for all panes when tmux sessions are re-attached. This is especially useful when attaching tmux session over SSH X session, as Vim clipboard refers to $DISPLAY when forwarding clipboard content through X11. See this commit and this commit for updating tmuxline in Vim sessions.
  • update_tmuxline.sh updates tmuxline when changing tmux sessions and the focus on tmux panes. This script does not deal with Vim session, as it is updated by the update_tmuxline augroup in vimrc. An important function is this augroup is UpdateTmuxlineByMode(), see this SO answer and this GitHub issue for more info.
Clone this wiki locally