less
is a termcap application, using the termcap interface to obtain all of the information it "knows" about a given terminal. Unless its developer introduces some hard-coded behavior (as done in a very few programs which I won't mention), less
will provide no support for those key combinations because they are not standard features (see for instance the termcap column of the capabilities listed in ncurses' terminfo(5)), and have no 2-character names assigned to them (see the terminal database for a summary of extensions).
By the way, referring to my answer and taking a quick look at less's source-code, I do not see anything that corresponds to left/right word movement (unless that is the intended meaning of the left/right shift A_LSHIFT
and A_RSHIFT
). git blame says those as well as the manual page comment about "word" date back to 2007 (version 394). These look more promising (from 2016):
SK(SK_CTL_RIGHT_ARROW),0, A_RRSHIFT,
SK(SK_CTL_LEFT_ARROW),0, A_LLSHIFT
but the checkin comment only says
commit e5c195113d1666ac506ea3f65545d436d96fe099
Author: Mark Nudelman <markn@greenwoodsoftware.com>
Date: Sat Oct 22 15:25:44 2016 +0000
New commands ESC-{ and ESC-} to shift to start/end of displayed lines.
Reading the code (in command.c) for shifting, I did not see anything that disagrees with the conclusion that less
scrolls by columns (single characters) rather than words, but OP's comment pointed to these:
ESC,SK(SK_LEFT_ARROW),0, EC_W_LEFT, /* ESC LEFTARROW */
SK(SK_CTL_LEFT_ARROW),0, EC_W_LEFT, /* CTRL-LEFTARROW */
ESC,'w',0, EC_W_RIGHT, /* ESC w */
ESC,SK(SK_RIGHT_ARROW),0, EC_W_RIGHT, /* ESC RIGHTARROW */
SK(SK_CTL_RIGHT_ARROW),0, EC_W_RIGHT, /* CTRL-RIGHTARROW */
which use space as a delimiter for "words". Perhaps when the developer made those changes, he had in mind imitating vi, which can do both (though vi's words are delimited differently).
The suggested *Escapeleft-arrow, etc., are provided using these lines from the table:
ESC,SK(SK_LEFT_ARROW),0, EC_W_LEFT, /* ESC LEFTARROW */
ESC,SK(SK_RIGHT_ARROW),0, EC_W_RIGHT, /* ESC RIGHTARROW */
However—the current program does not contain any assignments using those SK_CTL_RIGHT_ARROW
or SK_CTL_LEFT_ARROW
symbols. That would be done in lesskey, e.g., in this case statement (or close by, at any rate):
switch (*++p)
{
case 'u': ch = SK_UP_ARROW; break;
case 'd': ch = SK_DOWN_ARROW; break;
case 'r': ch = SK_RIGHT_ARROW; break;
case 'l': ch = SK_LEFT_ARROW; break;
case 'U': ch = SK_PAGE_UP; break;
case 'D': ch = SK_PAGE_DOWN; break;
case 'h': ch = SK_HOME; break;
case 'e': ch = SK_END; break;
case 'x': ch = SK_DELETE; break;
default:
error("illegal char after \\k", NULL_PARG);
*pp = p+1;
return ("");
}
Without assignments in the code, those are hard-coded only, not configurable.
The MSDOS / OS/2 configurations differ from the Unix one by having a (hard-coded) table of key codes:
#if MSDOS_COMPILER || OS2
static char k_right[] = { '\340', PCK_RIGHT, 0 };
static char k_left[] = { '\340', PCK_LEFT, 0 };
static char k_ctl_right[] = { '\340', PCK_CTL_RIGHT, 0 };
static char k_ctl_left[] = { '\340', PCK_CTL_LEFT, 0 };
and provides for using those in a case statement:
#if MSDOS_COMPILER || OS2
case SK_INSERT:
s = k_insert;
break;
case SK_CTL_LEFT_ARROW:
s = k_ctl_left;
break;
case SK_CTL_RIGHT_ARROW:
s = k_ctl_right;
break;
(note: still no assignments, hence the cases are unused), while in the termcap configuration, those symbols are not used at all. (termcap is "extensible", and if you took the trouble to invent 2-character mnemonics for your own use and modify less to implement those cases, it would do what you want).
Revisiting lesskey's manual page, it says this:
An action may be followed by an "extra" string. When such a command is
entered while running less, the action is performed, and then the extra
string is parsed, just as if it were typed in to less. This feature
can be used in certain cases to extend the functionality of a command.
For example, see the "{" and ":t" commands in the example below. The
extra string has a special meaning for the "quit" action: when less
quits, first character of the extra string is used as its exit status.
That implies that you could do something like this:
\e[1;5D noaction \e\e[D
\e[1;5C noaction \e\e[C
to map into an extra string which uses the predefined word-shift.
less
doesn't support (at least not out of the box) the standard escape sequences that Ctrl+arrow keypresses generate nowadays inxterm
and many other terminal emulators. It probably supports an older one instead. It would be lovely if you reported this toless
's developer, thanks in advance! – egmont Mar 15 '19 at 12:32