I think it'd be most useful if I took this a piece at a time. The general problem is: who is the key press intended for? The terminal, or the program running inside the terminal?
As an example, "screen", which is kindof a terminal, uses Ctrl+A as a prefix for its commands, to distinguish them from things going to the running program itself. (And provides a way to send Ctrl+A.)
gnome-terminal
has several keys that it captures to do various things, including some of the ones you ask about.
Also keep in mind that a terminal's "highlighting" is separate from the terminal's cursor position. Some terminals have no ability to highlight at all.
Now, taking this key combinations at a time:
left+right arrows to move left+right
ctrl+arrow to move an entire word
home/end to move to start/end of line
Move what left and right? Bash can be configured to do this, and typically is by default. Typically, these move the cursor position.
ctrl+c/ctrl+v to copy/paste
First: does copy/paste even make sense? If you're at a VT, you don't really have a clipboard, especially if X isn't running.
Some terminals can copy text in the output, and some will also "paste" by simulating you typing the contents of the clipboard. Ctrl+Shift+V, for example, is paste in gnome-terminal
, which may help. (And Ctrl+Shift+C is copy.) As discussed earlier, the big problem with Ctrl+C and Ctrl+V is they overlap with common terminal/program commands. (Ctrl+C is send interrupt (SIGINT) and Ctrl+V is verbatim.)
Some terminals also support two modes of copying data: a more normal "just copy", and what's known as "block select" or "block copy". (Hold Ctrl, and then drag while in gnome-terminal
for example.)
Additionally, xsel -b
can be used to pipe clipboard contents around. Depends on the exact situtation whether xsel
or the terminal's version of paste is more useful. See man xsel
.
shift+arrow to highlight text
shift+ctrl+arrow to highlight an entire word
Your terminal's highlight (if it has this capability) is separate from cursor position. Again, lack of available key combos is probably a factor. Keep in mind a highlight has two positions: either the start and end, or the upper left and lower right corners. How do you manage both?
Finally, note that many GUI terminals, double-clicking a word will highlight it. (And in X, copy to the primary selection.)
screen
, as an example, has keys to switch into a mode for moving around the buffer (previous output) and copy/pasting.
I think if you make adequate use of xsel
and the primary selection, you will find clipboard operations are both rare enough and complex enough to merit using the mouse.
Generally, no.
Specifically, any such capabilities will depend on multiple factors.
less itself runs inside a terminal environment, and doesn't really know of the clipboard at all.
Your terminal emulator provides clipboard interaction, but probably doesn't have much intelligence in terms of what's currently displayed inside the emulated terminal.
It probably isn't impossible to write a text-mode application that can make use of the X APIs to eventually interact with the clipboard, but it'd likely be a lot of work for very little gain, given that it's often quite easy to enlarge the terminal emulator window, or copy and paste multiple times.
In the specific case of less, consider removing less
from the equation entirely. If the file is not too large or otherwise inappropriate to just dump onto the terminal, just cat
it to the terminal instead, and use the terminal emulator's scrollback buffer to select the text you want to. With an appropriately sized scrollback buffer, that will allow you to copy all the text you want to copy in one operation.
Since we've found that you really are trying to just get a section of a text file, you can use a command like sed -n M,Np infile > outfile
to extract the range of lines M
through N
from the file named infile
. For example, to extract lines 10,000 through 20,000, you'd use sed -n 10000,20000p infile > outfile
. How can I extract a range of lines from a text file on unix? has additional suggested solutions for how to solve that problem.
Best Answer
Those aren't features of bash, they're features of the terminal driver. As such, they're specified by
stty(1)
.