Copy text from one tmux pane to another (using vim)
I have two files opened in vim, each in one tmux pane. I would like to copy let's say 10 lines from one file to another.
How can I accomplish this not using the mouse's
You could involve *tmux*, but there are generally simpler ways. Are both the Vim instances on the same (local?) machine? Usually, I would just use a temporary file for that (i.e. visually select the lines, `:w /tmp/lines`, then `:r /tmp/lines` in the other instance). Or, if your Vim knows how to talk to your system clipboard, you could use the `+` or `*` registers to avoid the temporary file.
You'll have to use tmux shortcuts. Assuming your tmux command shortcut is the default: Ctrl+b, then:
Ctrl+b, [ Enter copy(?) mode.
Move to start/end of text to highlight.
Start highlighting text (on Arch Linux). When I've compiled tmux from source on OSX and other Linux's, just Space on its own usually works. Selected text changes the colours, so you'll know if the command worked.
Move to opposite end of text to copy.
Alt+w Copies selected text into tmux clipboard. (On Mac use Esc+w.)
Move cursor to opposite tmux pane, or completely different tmux window. Put the cursor where you want to paste the text you just copied.
Ctrl+b, ] Paste copied text from tmux clipboard.
tmux is quite good at mapping commands to custom keyboard shortcuts.
See Ctrl+b,? for the full list of set keyboard shortcuts.
Thanks. Just a sidenode: The Alt + w did not work on Mac. Alt was mapped to Esc by default. Hence it is Esc+w.
@KaranThis is not true for me on OS X 10.10.5 with tmux 2.0, although alt+w doesn't copy the text either.
if you use `screen` shortcuts: `Ctrl + A [` (enter copy-mode), `Space` (start highlighting), `Enter` (end highlighting), `Ctrl + A ]` (paste).
Accessing tmux on ubuntu 16.04LTS, using putty as terminal on Windows 10. All the commands that @alexleach mentioned worked great
"y" also works and also copies to system clipboard as well which is what I prefer.
As noted in https://awhan.wordpress.com/2010/06/20/copy-paste-in-tmux/, if you have vi key bindings, step 5 should be replaced with `Enter` key.
what If I need to copy and paste to a text editor? For some reason it doesn't seem to pick up that selected text even after pressing 'enter' after selecting the text.
Note if you have in your `.tmux.conf` the lines `set -g mode-keys vi` and `set -g status-keys vi`, you can move with VI movement commands, enter selection mode with `v`/`V`, and copy the text with `y`.