PuTTY doesn't do that. It's a feature of xterm, and is one of many features of xterm not provided by PuTTY: sending different escape sequences depending on whether the Control and/or Shift key is pressed at the same time.
xterm-style modifiers for cursor keys are supported in ncurses by a extended terminal description (not part of conventional X/Open or SVr4 terminfo). However, PuTTY does not implement xterm-style modifiers in this case. For a long time, it used the Shift key to switch between normal and application modes for the cursor keys, and recently changed the modifier to the Control key:
commit 41e1a586fb956539a74bc446984a100e0138cd77
Author: Simon Tatham
Date: Sat Dec 8 08:25:32 2018 +0000
- swapping the arrow keys between normal (ESC [ A) and application
(ESC O A) is now done by pressing Ctrl with them, and _not_ by
pressing Shift. That was how it was always supposed to work, and
how it's worked on GTK all along, but on Windows it's been done by
Shift as well since 2010, due to a bug at the call site of
format_arrow_key() introduced when I originally wrote that function.
but that did not change the escape sequence used. In the change comment, ESC [ A
refers to the normal-mode up-arrow, and ESC O A
to the application-mode up-arrow.
ncurses provides an accurate terminal description for PuTTY, but in this case the terminal description is irrelevant because bash uses hard-coded escapes in .inputrc
(zsh does a little better, but also is lacking in this area--see the xterm manual). Even supposing that bash used the terminal description, the information is not available to bash because the terminal description's names cannot be read using a termcap application (such as bash). As mentioned, zsh is a little better, but it does not read extensions.
Using
infocmp -x xterm
you might notice kLFT5
, kRIT5
, kUP5
, kDN5
(which are the names given to the control-modified cursor keys--all extensions), but you will not find those in the putty
terminal description because PuTTY doesn't do that.
Best Answer
To support alternative key mappings you can use the GNU readline library's
inputrc
init file.Each user can have their own
.inputrc
file in their home directory. Or use global/etc/inputrc
to set it for all users.To check the current key map, enter verbatim mode (
Ctrl-v
) followed by the key to map. This will prevent theshell
from parsing and executing the key and provide the key sequence.E.g.
The
^[
sequence is equivalent to the[Esc]
key, so needs to be mapped ase\
.To test a new map use the
bind
command:Once this works, you can either add the
bind
command to your shell profile or add all the maps to your.inputrc
file.For Debian / Ubunutu based key mappings, add the following into your personal
~/.inputrc
file:Then log in again or start a new shell.