26

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!

kos
  • 41,268
Morten
  • 768
  • 2
  • 8
  • 14

5 Answers5

12

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.

Akisame
  • 3,343
6

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.
d a i s y
  • 5,551
5

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

blue112
  • 179
  • 4
2

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

ymbirtt
  • 269
  • 2
  • 8
0

It can be done with emacs.

  1. Open emacs
  2. Alt-X + term: opens a terminal in a new emacs buffer
  3. Ctrl-C+Ctrl-J: enter line mode (more details on the modes below)
  4. Select the desired text
  5. Alt-W: copy the text
  6. Ctrl-C+Ctrl-K: go back to char mode
  7. Ctrl-Y: paste

Remarks on line-mode and char-mode

In char-mode, each character you type is sent to the terminal (like in any terminal) and most emacs shortcuts are disabled (to enable terminal shortcuts). In particular, don't be surprised if shortcuts to change the buffer do not work. To change the buffer, you must first enter line mode. In line mode emacs behave like in a normal emacs buffer. More details here.

Zach
  • 195