Select/copy/paste in terminal using only the keyboard

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.


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.

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

Tags:

Command Line