A few days ago, I wanted to copy text from my tmux shell.
I came across an excellent blog post called Everything you need to know about Tmux copy paste - Ubuntu, which listed all the steps you need to take.
First, the default behavior:
- Enter ‘copy mode’ by pressing CTRL
- Use the arrow keys to go to the position from where you want to start copying. Press CTRL
+SPACEto start copying.
- Use arrow keys to go to the end of text you want to copy. Press ALT
+w or CTRL
+w to copy into Tmux buffer.
- Press CTRL
+b, ] to paste in a possibly different Tmux pane/window.
Please note that
CTRL+B is the default tmux “prefix”. You can adjust it to a different key combination, if you want 1.
## ~/.tmux.conf ## Use vim keybindings in copy mode set-option -g mouse on setw -g mode-keys vi set-option -s set-clipboard off bind P paste-buffer bind-key -T copy-mode-vi v send-keys -X begin-selection bind-key -T copy-mode-vi y send-keys -X rectangle-toggle unbind -T copy-mode-vi Enter bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel 'xclip -se c -i' bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel 'xclip -se c -i'
- Now you can enter copy mode normally with
- Navigate the copy mode with vi-like-key bindings (
dfor down, etc.)
vto start copying.
Enterto copy the text into the tmux buffer. This automatically cancels copy mode.
- Paste into the buffer with
<prefix>+P(make sure that it’s uppercase P).
Or alternatively, use the mouse to copy text after you’ve entered copy mode.
The above commands use
xclip, a Linux command line tool for X11. You can replace
xclip -se c -i with a platform-specific command like
pbcopy (MacOS) or