vim – How to Copy Text from One tmux Pane to Another Using Vim

copy/pastetmuxvim

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 Copy -> Paste ?

Best Answer

You'll have to use tmux shortcuts. Assuming your tmux command shortcut is the default: Ctrl+b, then:

  1. Ctrl+b, [ Enter copy(?) mode.

  2. Move to start/end of text to highlight.

  3. Ctrlspace

    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.

  4. Move to opposite end of text to copy.

  5. Alt+w Copies selected text into tmux clipboard. (On Mac use Esc+w.)

  6. Move cursor to opposite tmux pane, or completely different tmux window. Put the cursor where you want to paste the text you just copied.

  7. 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.

Related Question