Terminal – Why Control-Left and Control-Right Don’t Navigate by Word in Less

input-methodlessterminaluser input

In less's line editing mode, the left and right arrow keys move the cursor backwards and forwards. I was hoping to use these together with the control key to navigate by word, as promised by man less.

       ^LEFTARROW [ ESC-b or ESC-LEFTARROW ]
              (That is, CONTROL and LEFTARROW simultaneously.)  Move the cursor one word to the left.

       ^RIGHTARROW [ ESC-w or ESC-RIGHTARROW ]
              (That is, CONTROL and RIGHTARROW simultaneously.)  Move the cursor one word to the right.

Unfortunately, this seems not to work in my terminal. (Tilix 1.8.3, VTE 0.52, GTK 3.22.30 on Fedora 28). Instead, pressing Control-left prints something I don't recognise. In the example below, I typed alpha beta and then immediately pressed Control-Left. This added ESC[1;5D to the line.

[1]

Is there some misconfiguration going on here? In other applications (e.g. vim) Control-Left and Control-Right navigate by word as intended.

FWIW, Ctrl + left/right arrow keys issue, might be related as might Arrow keys in less

Best Answer

Because you are not using OS/2

I am not kidding.

The OS/2 input handling code in less has a "special key" mapping for the ⎈ Control+ and ⎈ Control+ chords to its internal SK_CTL_LEFT_ARROW and SK_CTL_RIGHT_ARROW events.

The Unix code simply has no equivalent mapping. It relies upon termcap, and termcap is notoriously deficient in this area.

What is in square brackets in the doco is right, and what is in parentheses is wrong. You'll have to use ⎋ Escape B, ⎋ Escape F, ⎋ Escape (sic!), and ⎋ Escape (sic!) sequences (not chords, note) until someone makes less better. Please file a report.

(In some terminal emulators, you can configure a modifier key to cause an ⎋ Escape to be prefixed. This is not true for all terminal emulators and terminals, in particular the ones whose input control sequences are being emulated here (which, rather, report modifiers in the CSI sequence), and the important part is that the first character received by less from the terminal is . less itself has no notion of such a modifier.)

Further reading

Related Question