Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to use the keyboard in order to select some text in the terminal windows that is not in the currently edited line? (for example, in order to copy part of previous command output).

share|improve this question
up vote 5 down vote accepted

As far as I know, neither of the "big three" terminal emulators can do that, but both screen and tmux offer a scrollback buffer you can access via keyboard.

GNU screen

screen's Prefix key is Ctrl+A per default, but all of that is customizable, so with a default config:

  1. Enter copy mode with Ctrl+A[.

  2. Move cursor around with vi motions: h, j, k, l, 0, ^, $, H, M, L, w, b, e, /, ?, g and G all work (see man screen under copy for more info on key bindings).

  3. Start selecting with Space, move around, and stop selecting with Space again. This will leave copy mode.

  4. Paste the selected text with Ctrl+A].


tmux behaves pretty much the same, except it uses some different keys per default:

  1. Enter copy mode with Ctrl+B[.

  2. Move cursor around with , , , , PgUp, PgDown etc. (see man tmux | less -p '^WINDOWS AND PANES' for the list of copy-mode bindings).

  3. Start selecting with Ctrl+Space, move around, and stop selecting with Meta+w. This will leave copy mode.

  4. Paste the selected text with Ctrl+B].

share|improve this answer
Thanks, I'll try that :-) – Itay Jun 15 '11 at 12:09
copy screen data works perfectly, thanks – Fedir Mar 30 '12 at 15:15

Depends on the terminal you use. It is possible in shell mode in emacs.

share|improve this answer
I am using gnome-terminal, do you know if it is somehow possible? – Itay Jun 14 '11 at 9:22
@Itay Nope. I use mouse :) – Rajish Jun 14 '11 at 10:11
Thanks, the mouse slows me down :) but I guess I'll have to live with it :) – Itay Jun 14 '11 at 10:33
@Itay - While you still have to use the mouse to select, you can use Ctrl+Shift+C to actually make the copy. – Shauna Jun 14 '11 at 12:14

It's not quite what you're asking, but if you redirect output through xclip, you can pull it from the clipboard and edit it. I never thought about using it to minimize keyboard use.

$ echo "this is the primary buffer" | xclip -selection "primary"
$ cat << EOF > primary.txt
> this is the primary buffer

Under gnome-terminal, I can use shift-insert to paste into the here-file. From the man page xclip -selection "clipboard" does the real clipboard instead of the x buffer.

I can't seem to get it working with tee though... hmmm.... that's kind of important.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .