24

I am using Ubuntu 16.04 with tmux 2.1. Mostly I split the screen in two tmux windows split vertically. Frequently I need to copy long pieces of text from tmux window and paste in sublime text/browser. I have a feeling that xsel/xclip could be used to achieve the same. However, most of the how-to's floating in the Internet are severely bloated, trying to explain intricate configuration option without really explaining:

  • What exactly do I need to configure in tmux.conf?
  • How do I select a piece of text in tmux window?
  • How do I copy the selected piece of text?
  • How do I paste the text from system clipboard to text editor/browser?

I don't want to be a tmux guru. All I want to get the job done in simplest possible way. Any clue how to do that?

sherlock
  • 2,397
  • 3
  • 27
  • 44
  • 4
    really excellent article on all things tmux copy paste ubuntu, pretty much written for this question: https://www.rushiagr.com/blog/2016/06/16/everything-you-need-to-know-about-tmux-copy-pasting-ubuntu/ – Jeff Puckett Nov 19 '21 at 05:17
  • May refer to https://stackoverflow.com/questions/17255031/how-to-copy-from-tmux-running-in-putty-to-windows-clipboard – hellohawaii Jul 06 '23 at 11:41

4 Answers4

6

I personally am using Ubuntu 18.04 in WSL2 . However this solution will work on Ubuntu 16.04 also.
I have been using tmux-yank for copything text from tmux buffer to system clipboard. You would first need to set up Tmux Plugin Manager. Follow this link.

Then set add tmux-yank plugin to your .tmux.conf file , see here.

1

You can start by looking at the example configurations at: /usr/share/doc/tmux/examples$

You can also look at the current key bindings using ctrl+b+?.

You can change these default key bindings in the .tmux.conf file. It depends on your settings how you select a piece of text in tmux window. You can map the key bindings as per vim. Enter the copy mode (ctrl+b + [), scroll to the start/end of the text you want to copy to the tmux clipboard, press v (provided the key bindings as per vim) to start copying. move to the other end of the text, press y to yank the text. press ctrl+b+] to paste the text.

I am trying to figure out how to copy/paste from system clipboard on this version. Will update my answer if I have any luck.

truth_seeker
  • 345
  • 4
  • 14
0

Searching tmux copy clipboard this question was shown and I'd like to share one of the ways how to deal with the problem if you're using tmux within VSCode. I use selection with the mouse with set -g mouse on setting in .tmux.conf; to get the selected fragment which is stored in tmux buffer I do cat | code - and paste in the running cat with Ctrl-b + ]; pasted fragment occurs in VSCode editor too, then it's easy to copy from the window.

amordo
  • 449
  • 5
  • 15
-5

On tmux 1.8 running in ssh session under Putty 0.73 on Windows, below works for me.

COPY: Use ctrl+b,] got to start line, press Spacebar (it will start selection and highlighting text), use arrow or PageUp to go to end line, press Enter to get all selected text in buffer.

PASTE: ctrl+b,]

  • 5
    This answers copying and pasting within `tmux`. OP is looking for a way to copy to system clipboard for use elsewhere. – axolotl Oct 05 '21 at 14:30