Bash – Using ctrl-arrow keys with PuTTY and screen

bashgnu-screenputty

I searched and couldn't find a solution for this anywhere. I'm using PuTTY from Windows to connect to various servers where I run bash and screen. It seems bash works fine with ctrl-arrow keys to jump word-to-word on the command line but within screen it's not working. Not in screen, ctrl-left sends "^[OC and ctrl-right is "^[OD". Within screen I instead get "^[[C" and "^[[D", which appears to be the codes for just the left/right arrow keys. Is there any way to get screen to recognize ctrl-arrow keys when using PuTTY? (FYI, I don't remember having this problem when using gnu-terminal in linux instead of PuTTY).

UPDATE: It appears PuTTY is the problem as it is not sending the escape codes that are necessary for this to work. I'm giving up for now and using Cygwin+mintty.

Best Answer

Edit:

Here's what worked for me:

  • My ~/.bashrc sets TERM=xterm (mine happens to be TERM=xterm-256colors) overriding screen's TERM=screen
  • I set PuTTY > Terminal > Features > Disable Application cursor keys mode to checked
  • I enter tput smkx at the Bash prompt
  • Now Ctrl-Arrow keys jump word-by-word

  • For informational purposes, if I do:
    tput smkx | hexdump -c
    I get
    0000000 033 [ ? 1 h 033 =
    and
    tput rmkx | hexdump -c
    gives me
    0000000 033 [ ? 1 l 033 >

I think there's a way to rework this into something a little better, but it's what I've got so far and it seems to work.

Original answer:

From info screen:

Each window in a `screen' session emulates a VT100 terminal, with some extra functions added. The VT100 emulator is hard-coded, no other terminal types can be emulated.

And VT100s don't have Ctrl-Arrow keycodes.