I am accessing a linux box via ssh
using putty
.
Key combinations work fine when I'm not running screen
.
However, Ctrl key combinations do not work under a screen
session.
In fact, a Ctrl–any key is registered the same as the same key without the Ctrl combination.
I know this by typing Ctrl–V and then a Ctrl–key combination to figure out what characters are sent to my terminal.
For example, Ctrl–◄ (left arrow) gives me ^[[D
on screen
(screen256-color term). ◄ gives me the same result.
Weird thing is that Alt–key combinations work fine.
In particular, I would like to get the 'forward-word' and 'backward-word' key bindings working under screen
.
I have tried modifying .inputrc
to work with various terminals. As such, my .inputrc
looks something like this:
$if term=xterm
'xxx' : forward-word # xxx key gotten from Ctrl-V
'xxx' : backward-word
$endif
$if term=screen-256color
...
...
I have also tried various terminals by setting the TERM
of my bash
profile, setting TERM
on .screenrc
, and setting the Putty
keyboard terminal mappings. The obvious ones, linux
and xterm
, don't work. However, I haven't tried every permutation of settings for obvious reasons.
Additional info:
I stand corrected, arrow key combinations are the only combinations that do not work.
The distro is RHEL 6.
.screenrc:
term xterm # tried other terms as well
shell -$SHELL # login shell to reload configs
caption string "%w"
hardstatus alwayslastline "%{b kw}%H %{r}%1` %{w}| %{g}%c %{w}| %{y}%d.%m.%Y %{w}| %{g}%l %{w}| %{-b kw}%u %-Lw%{= rW}%50> %n%f %t %{-}%+Lw%<"
vbell off
defscrollback 5000
Putty's default keyboard mode ESC [n~
.
Taken from the putty manual:
"In the default mode, labelled ESC [n~, the function keys generate sequences like ESC [11~, ESC [12~ and so on. This matches the general behaviour of Digital's terminals."
Interestingly, what's actually sent by Putty
(by following the first answer on https://superuser.com/questions/342848/cant-get-keyboard-to-work-correctly-in-putty), is
^[0D : left-arrow
^[[D : Ctrl-{left-arrow}
Since the they are different, I guess putty
isn't the issue then?
FWIW, I tried changing the Application Cursor key mode settings on Putty, but to no avail. I also tried using tmux
, only to encounter the same issue.
Best Answer
In its default configuration, PuTTY sends cursor keys in normal mode, e.g.,
^[OA
while screen sets the cursor keys to application mode, e.g.,^[[A
.That is done by screen's sending the escape sequence to turn on the keypad (in termcap
ks
, terminfosmkx
). That happens to turn on the application mode for both the numeric keypad and the cursor keys, because both are present in theks/smkx
capability. screen uses this capability if it is present, when initializing the terminal. screen also follows up by sending the string in the termcapCS
capability if it is set, hinting that the original design was to use terminal descriptions where only the keypad was initialized byks/smkx
.You notice this difference because your key bindings expect the strings sent by the cursor keys in normal mode. If you modified the terminal description for screen to omit the part which changes the cursor keys, you could continue to use those bindings.
For instance, you could do this:
and change the assignment
to
then
to compile the modified description. If you do this as your (non-root) user, tic will put the compiled description in your
~/.terminfo
directory. There are drawbacks to this approach, and usingtput
to obtain key-binding information is preferable. But it is simple.Further reading: