I used to select text via mouse click+drag but I want to know if I can do the same thing via the keyboard only?

I am talking about selecting text with the help of the keyboard on gnome-terminal, etc.


5 Answers 5


If you use Urxvt, you can extend the keyboard functionality of the terminal using urxvt-perls, a collection of scripts that enables:

  • selecting text
  • passing URLs to your $browser
  • searching your scrollback
  • and yanking and pasting to and from your clipboard

Essentially, with urxvt-perls installed, you can dispense with your mouse entirely.


For GNOME Terminal 3.30.1 in Ubuntu 18.10: use "find" (Ctrl-Shift-F), enable regular expressions and search for a regular expression covering the range of text you wish to select. Once you have it, you can close the "Find" window by pressing Esc and copy your text using Ctrl-Shift-C.


It depends on your terminal. If this is something important to you, you could consider Emacs term-mode which gives you the full text-manipulation capability of the editing environment. It's possible that you consider that to be overkill, of course!


You could use neovim and nvim_terminal_emulator

Nvim embeds a VT220/xterm terminal emulator based on libvterm. The terminal is presented as a special buffer type, asynchronously updated from the virtual terminal as data is received from the program connected to it.


The answers to xterm dump of full scrollable window content make it sound like you could write your own application to do it. When you invoke the application from a terminal, it would let you use (readline-like) keystrokes to move a visible selected area around the terminal. Finally, press a key to exit, leaving the current highlight as your selection.

Allowing your application to know the content of the terminal is tricky. The link above mentions several possible ways to do it. I'm most beguiled by the idea of using script to do it. Perhaps on install, your application would need a script invocation added to .bashrc, so that all interactive terminals capture their content to a file. Then when invoked, use the correct one of those files to determine the content of its parent terminal.

This sounds really fiddly to get right. Your application would have to invisibly render the stream to a 2D array, to figure out what the terminal currently looks like. As part of that, it would have to account for newlines and tabs, obviously, and for zero-width characters such as changing colors, and understand all the control characters such as "position cursor".

On the upside, it might work anywhere 'script' could be run, so long as the terminal supports ANSI, which is about all of them apart from the old Windows "cmd.exe".

You must log in to answer this question.

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