Selecting text in the terminal without using the mouse

If you are using one of the shells that understands emacs keys (bash, csh, etc.) then you can copy the current command by:

  1. control-A will take you to the beginning of the line.

  2. control-K will kill the whole line that you have just entered.

  3. control-Y will yank the text back.

Then later you can control-Y yank the text back to insert the text back as input to the shell command line editor.

See man bash and then when it comes up, type /emacs followed by a couple of n's (next) to move you forward to the READLINE section.


Bind following shortcut:

bind '"\C-p": "\C-e\C-u xsel <<"EOF"\n\C-y\nEOF\n\C-y"'

Now after using Crtl+P your line will be copied into clipboard. You can paste it in terminal using:

xsel

And into any X application using middle mouse button or Shift+Insert.


The closest I can think of is Ctrl+u, Ctrl+y
This would delete from cursor to the beginning of line, then paste from the readline buffer. This isn't exactly the same as the clipboard though, but you would be able to paste inside the shell, if that is what you need.