Copy, with line wrapping!
If you've been trying to copy/paste text from a multi-pane
tmux session with the mouse, you've probably been pretty pissed at the blissful ignorance a terminal application has of the rodent in your hand.
The alternative, which is quote-unqoute native copy/pasting using copy-mode takes a bit to get used to. So this is one solution for copying and pasting lines from a session with correct line wrapping behaviour, albeit keyboard only.
Since copy-mode has similar concepts of marks, regions, and temp buffers to Emacs .. you'll probably find it straight forward if you're familar with Emacsen. For people using vi-mode in
tmux, the same still applies but obviously the default key bindings will differ alot from what I show below.
C-a as the send-prefix key even though
C-b is the default. The word on the street is
tmux developers don't even use
The following steps work for me using a
OSX/iterm2/tmux/dvtm combo, if you really need the mouse, you can try out: http://code.google.com/p/iterm2/wiki/TmuxIntegration
1) Follow the instructions here: https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard to get
pbcopy/pbpaste working from inside of
2) Doctor the following code snippet for your tastes and add it to
# Set bash to whichever shell you are using, zsh for example set-option -g default-command "reattach-to-user-namespace -l bash" # Remove the default binding for copy-selection, substitute emacs-copy with vi-copy if you're using vi-mode unbind -t emacs-copy M-w # Bind a different key to copy-selection bind -t emacs-copy c copy-selection # Bind prefix-M-w to copy-selection, save selection to buffer, and then pipe it's contents to pbcopy bind M-w send-keys c\;\ save-buffer /tmp/tmux-buffer\;\ run-shell "reattach-to-user-namespace -l bash -c 'cat /tmp/tmux-buffer|pbcopy'"
The above code removes the default copy-selection key in copy-mode (
M-w in my case) and substitutes it with a prefixed version:
C-a M-w. This is because (without patching) tmux cannot bind multiple commands to a key under a specific key-table, only globally.
3) You can check what keys you currently have set for copy-mode by using
list-keys -t vi-copy|emacs-copy to list mode key bindings or use
setw -g mode-keys vi|emacs to switch modes.
To copy the desired piece of text from a tmux pane to your OS' clipboard, you will need to do the following:
- Mark the start of the region using
- Use next/previous char/line to expand the marked region until it encompasses what you want to copy
C-a Alt-wto copy the region into a buffer (success will cause the highlighted region to become unselected)
C-]to paste the buffer to the current cursor position (outside of copy-mode)
tmux homepage http://tmux.sourceforge.net/
Default emacs-copy keys:
C-a [Copy mode
C-a Alt-wCopy marked region into buffer
C-a ]Paste saved buffer
ESCExit copy mode