As the question is posed, this is probably related to the ncurses FAQ My cursor keys do not work.
nano initializes the terminal to application mode, while the shells do not, leaving them in normal mode.
You're not identifying the terminal (emulator), but likely its "normal" mode is incorrectly using CSI (escape-[) rather than SS3 (escape-O).
However, from followup comments, conflicting information is given. The programs (bash, tcsh, zsh) which are given as non-working are unsurprising since none of them uses the terminal database to obtain information on modified keys. Some of this is documented in the xterm manual (Special keys). None of that is documented in any of the shell's manuals. To the extent that it "works", they rely upon literal strings in their configuration. Since zsh (tries to) use the terminal database, but does not read the extended information—see source—there's no luck there.
In a GUI, the default "Terminal" likely is gnome-terminal... which sets TERM
to xterm-256color
. That (mostly) works, though if there were documentation for gnome-terminal
, one would expect to find its quirks duly noted.
nano uses the terminal description; grep'ing for (calls to the function calling) tigetstr
shows how it uses this information (see source):
src/nano.c:1233:int get_keycode(const char *keyname, const int standard)
src/nano.c:2389: controlleft = get_keycode("kLFT5", CONTROL_LEFT);
src/nano.c:2390: controlright = get_keycode("kRIT5", CONTROL_RIGHT);
src/nano.c:2391: controlup = get_keycode("kUP5", CONTROL_UP);
src/nano.c:2392: controldown = get_keycode("kDN5", CONTROL_DOWN);
src/nano.c:2394: controlhome = get_keycode("kHOM5", CONTROL_HOME);
src/nano.c:2395: controlend = get_keycode("kEND5", CONTROL_END);
src/nano.c:2397: controldelete = get_keycode("kDC5", CONTROL_DELETE);
src/nano.c:2398: controlshiftdelete = get_keycode("kDC6", CONTROL_SHIFT_DELETE);
src/nano.c:2400: shiftup = get_keycode("kUP", SHIFT_UP);
src/nano.c:2401: shiftdown = get_keycode("kDN", SHIFT_DOWN);
src/nano.c:2403: shiftcontrolleft = get_keycode("kLFT6", SHIFT_CONTROL_LEFT);
src/nano.c:2404: shiftcontrolright = get_keycode("kRIT6", SHIFT_CONTROL_RIGHT);
src/nano.c:2405: shiftcontrolup = get_keycode("kUP6", SHIFT_CONTROL_UP);
src/nano.c:2406: shiftcontroldown = get_keycode("kDN6", SHIFT_CONTROL_DOWN);
src/nano.c:2408: shiftcontrolhome = get_keycode("kHOM6", SHIFT_CONTROL_HOME);
src/nano.c:2409: shiftcontrolend = get_keycode("kEND6", SHIFT_CONTROL_END);
src/nano.c:2411: altleft = get_keycode("kLFT3", ALT_LEFT);
src/nano.c:2412: altright = get_keycode("kRIT3", ALT_RIGHT);
src/nano.c:2413: altup = get_keycode("kUP3", ALT_UP);
src/nano.c:2414: altdown = get_keycode("kDN3", ALT_DOWN);
src/nano.c:2416: altpageup = get_keycode("kPRV3", ALT_PAGEUP);
src/nano.c:2417: altpagedown = get_keycode("kNXT3", ALT_PAGEDOWN);
src/nano.c:2418: altinsert = get_keycode("kIC3", ALT_INSERT);
src/nano.c:2419: altdelete = get_keycode("kDC3", ALT_DELETE);
src/nano.c:2421: shiftaltleft = get_keycode("kLFT4", SHIFT_ALT_LEFT);
src/nano.c:2422: shiftaltright = get_keycode("kRIT4", SHIFT_ALT_RIGHT);
src/nano.c:2423: shiftaltup = get_keycode("kUP4", SHIFT_ALT_UP);
src/nano.c:2424: shiftaltdown = get_keycode("kDN4", SHIFT_ALT_DOWN);
zle-line-init() echoti smkx
inzsh
? – Stéphane Chazelas Dec 16 '22 at 13:06echoti smkx; STTY='-icanon -echo min 0 time 20' od -vtc -tx1
andechoti rmkx; STTY='-icanon -echo min 0 time 20' od -vtc -tx1
within zsh where you press both Left and Ctrl+Left (ends after 2 seconds)? – Stéphane Chazelas Dec 16 '22 at 13:08