Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

These are the standard text editing keyboard shortcuts that I use constantly whenever editing text in, literally, any linux application other than terminal emulators:

  • left+right arrows to move left+right
  • ctrl+arrow to move an entire word
  • home/end to move to start/end of line
  • ctrl+c/ctrl+v to copy/paste [some terminals can use shift-ctrl-C/shift-ctrl-V; this is a good substitute]
  • shift+arrow to highlight text
  • shift+ctrl+arrow to highlight an entire word

I have never found a combination of shell plus terminal emulator that allows the last two items on this list, and it drives me nuts. Obviously terminal emulators support highlighting (the mouse can do it), and they support the use of the ctrl and shift keys as modifiers (they can be used to move the cursor an entire word, and to capitalize letters, respectively; [edit:] they can even be used together to copy/paste with shift-ctrl-C and shift-ctrl-V), so what is the issue preventing this functionality? I have several questions:

  • Is this an issue with my terminal emulator, or with my shell (bash, though I'm willing to change)?
  • Why do terminal emulators/shells not conform to this otherwise universal standard?
  • If there is an actual reason, is it ancient and obsolete, or is it still relevant to a significant number of desktop linux users?
  • Is there any kind of workaround?
  • Is there some obscure program I can use that supports this?
  • Is it feasible to modify the source of, say, gnome-terminal to support this?

I know text can be copied/pasted with the mouse, that's not what I'm asking about. I'm asking why I can't do these things with the keyboard in a terminal emulator.

share|improve this question
    
Note that selecting text with the mouse does not change the cursor position. If you'd mix in text selection with entering regular commands on the keyboard, it'd just be really confusing beyond the boundaries of the command you just typed and not yet executed. Are you able to select text beyond the boundaries of the text box on a web page with the keyboard? Please also note that there are programs like screen that allow entering a different mode that has text selection for the entire terminal, but of course does no longer allow entering commands. –  Daniel Beck Feb 22 '13 at 17:25
    
Daniel: the Matlab console, for example, is a CLI that allows text highlighting with the keyboard. It works perfectly in my experience; it allows selection beyond the current not-yet-executed command if desired, personally I have little use for that. –  monguin Feb 22 '13 at 17:38
    
    
and here as well stackoverflow.com/q/312213/1172302 –  Nikos Alexandris Jul 5 '13 at 8:03

2 Answers 2

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.

share|improve this answer
1  
I appreciate the time you took to write out your answer, but somehow I don't feel like I have any greater understanding of why this is not an available feature in terminal emulators. You pointed out a new idea to me - that a terminal emulator is unique in that it can run other programs - but I don't understand why only a select subset of key combinations are impossible to make available to the user. –  monguin Feb 25 '13 at 16:35
1  
Terminal emulators emulate physical terminals. They were not created from scratch to provide a command-line interface. Things like Control-C had established meanings long before Microsoft decided to co-opt them as keyboard shortcuts, and terminal emulators must adhere to them. –  chepner Feb 28 '13 at 20:53
1  
I think the devil is in the details here. It's not impossible: screen has a mode to do what you want, I think. But to accomplish it, you have to switch into a "I want to select things" mode. gnome-terminal would have similar issues: they probably didn't implement it because it isn't exactly something you're doing. Keep in mind the shell isn't the only program running: any program could be running, and it could want to use any key sequence that you might use for copy/paste for it's own purposes. screen has ways to send the keys it overrides, and gnome-terminal tries to not step on toes. –  Thanatos Mar 1 '13 at 21:58
1  
Block select is a means of selecting a rectangle: Hold control and drag in gnome-terminal, and you should immediately see how it's different. Most GUI terminal emulators have this capability, and most advanced text editors to as well. (See Visual block in vim, for example.) –  Thanatos Mar 1 '13 at 21:59
1  
Ah, then I'm familiar with block select, but wasn't aware of the name. I'm also not aware of a GUI keyboard shortcut for that action, so it seems unnecessary to invent one for the sake of answering my question. I appreciate everyone's comments here, but as I'm still unsatisfied, I suppose all I can do now is dig into the source myself... –  monguin Mar 1 '13 at 22:07

I'm not an expert of terminal emulators but...

applications like bash (readline) running into a terminal emulator know nothing about the running X window system and the X window they are within, they know stdin and stdout on a terminal device (ttyS/ttyUSB/tty/pts on linux).

The problem isn't show some highlighted text but how to let know the X window application (the terminal emulator) that text been selected, through these terminal devices.

I guess the X terminal application open one of those devices in input and output and then translate X key events to properly output (from X side) input (from bash side). Viceversa the bash output stream to the X terminal as input, here the X terminal process this input to move the cursor, fill the backround with some color, according with the bash application output.

For my knowledge escape codes may be used to control special behaviors, like clear, fill the background, move the cursor, and maybe some custom escape code could be added to let know the X terminal that a text from row,col to row,col has been selected, just an example, maybe instead the selected text could just be returned (an implementation detail).

I guess not being a standard definition you'll have to patch every application you want to support it to know about the key combination has pressed and output the appropriate escape code, the readline if you want it in the bash, the X terminal emulator on the other side to process properly the escape code (and finally send the information to the clipboard). Probably implementing this as a terminal capability would save you from patch every single application. I hope (and guess) the terminal device drivers in the kernel want to know less as possible about escape codes, so if you are lucky no patch will be required.

The X terminal draw the output, so it easily know, when you use the mouse, what text/characters are you selecting.

A graphic text widget know everything about its X window that why it is so easy to implement select&copy.

EDIT

Here this urxvt-9.16-image-display patch could be a good start point to understand what is needed to support new escape codes. http://lists.schmorp.de/pipermail/rxvt-unicode/2013q1/001736.html

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.