10

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

8

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

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

1

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

  • 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
0

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
> EOF

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.

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.