I'm looking for a way to select, copy and paste the text in the terminal completely without the mouse.

I've been using tmux until now, but I find its key combinations a bit complex for everyday use of copy & paste, and I'm now looking for alternatives.

Do you guys have any suggestions?

To be clear, this is not about piping to the clipboard but about selecting the text as it's possible in e.g. tmux!

  • See my answer here: askubuntu.com/a/756348/295286. Ive made a function that will copy whatever text is in front to clipboard. That works for copying the commands. As for output, it has to be piped – Sergiy Kolodyazhnyy Apr 20 '16 at 13:28
  • 2
    Okay guys this has nothing to do with stdout- it's about moving a cursor to some previous printed text Select it and Copy/paste it to the current line of input in the terminal:-D Sorry for not being more precise in description. – Morten Apr 21 '16 at 6:11
  • The best way to add additional information to your question is by editing it, with the edit button. It is better visible that way, and comments are mainly for secondary, temporary purposes. Comments are removed under a variety of circumstances. Anything important to your question should be in the question itself. – guntbert Apr 29 '16 at 19:01

Consider xclip, which is a command-line interface to the X clipboard, and is available with sudo apt-get install xclip.

You may have noticed that in Ubuntu, if you select some text and then press the middle mouse button, that text will get pasted into whatever input is in focus. xclip hooks right into that, so if you run seq 10 | xclip -i then middle-mouse somewhere, you'll paste the numbers 1 to 10. If you were to select my username then run xclip -o | cowsay, you'll get a cow saying the word "ymbirtt".

| improve this answer | |
  • 5
    I'm surprised this answer is accepted. @morten specifically pointed that this is not about piping to the clipboard but about selecting the text as it's possible in e.g. tmux. It seems like the answers from @daisy and @blue112 are on point. – Tad Lispy Oct 10 '17 at 9:16
  • 1
    @TadeuszŁazurski, so am I, honestly. xclip is a really good tool that complements the existing answer, but I'm not sure it's the answer – ymbirtt Oct 10 '17 at 9:58

I always use Ctrl+Shift+C and Ctrl+Shift+V to copy and paste in my (non tmux) terminal.
You can change these keyboard shortcuts in the keyboard preferences of your (non-tmux) terminal.

If however you want to keep using tmux you can also change the keyboard shortcuts of tmux by adding commands to ~/.tmux.conf. simply add the following in that file:

bind-key -n [shortcut. for example Ctrl+v is C-v] [what you want to do. for example 'new-window' etc]

It will look like this

bind-key -n C-t new-window

You don't need the command prefix key to execute the commands in the ~/.tmux.conf file.

For more info about the things available for ~/.tmux.conf check this link

Very rudimentary copying and pasting can be done using this however for a bit more usefulness I recommend using a Vim-style copy/paste config.
Enabling a Vim-style of copy/paste can be done with this config file or another config file. These do however require the use of the prefix key.
Someone even made a tmux extension to simplify the copy/paste action to the system clipboard in tmux. It might be worth a look.

If you want an alternative for Tmux you might try dvtm (sudo apt-get install dvtm dtach). I haven't used it myself but it looks like it has similar options.

| improve this answer | |

To copy, use Ctrl+Shift+C

To paste, use Ctrl+Shift+V or Shift+insert

Another way to do this:

First run command screen, after then can do following steps:

  • Press Ctrl+a+Esc It will put the screen in copy mode.
  • Now, move the cursor to the beginning of the section to copy & hit enter.
  • then, move the cursor to the end of the section to copy & hit enter.
  • Now, press Ctrl+a+] to paste.
| improve this answer | |
  • 7
    Great, but to copy something you must have it selected first. How do you select text without the mouse ? – Ponytech Apr 20 '16 at 8:36
  • 1
    @Ponytech I tried to do in gnome-terminal without run any command like screen but I couldn't. – d a i s y Apr 20 '16 at 9:18
  • Using screen is the only way I also found so far. Thanks for the update – Ponytech Apr 20 '16 at 9:43
  • question is about selecting text with kb – senseiwu Jul 24 at 8:08

You could use screen selection mode.

Enter a screen session using screen command.

Then, use Ctrl+a and Esc to enter into the selection mode.

You can then move your cursor, select some text using space, quit the selection mode, and paste it when you want with Ctrl+a and ].

More information here: http://web.mit.edu/gnu/doc/html/screen_11.html

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.