Using ctrl-arrow keys with PuTTY and screen

Solution 1:

As mentioned in here, u can put in ~/.inputrc:

"\eOD": backward-word
"\eOC": forward-word

It worked for me.

Solution 2:

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.


Solution 3:

I'm somewhat surprised that you got Putty to send ctrl-arrowkeys correctly even without using screen, as that has never worked for me. My solution was to switch to using alt-arrowkeys (meta-arrowkeys), which I believe have the same forward-word / backward-word binding in bash by default, though I had to issue a couple extra commands for zsh to recognize them:

bindkey "^[^[[C" forward-word      # Meta-RightArrow
bindkey "^[^[[D" backward-word     # Meta-LeftArrow

Solution 4:

In case others find this old question like I did, a more recent solution:

Ctrl and arrow keys doesn't work in putty! What do I do?

putty inverts the sense of the cursor key mode on ctrl, which is a bit hard for tmux to detect properly. To get ctrl keys right, change the terminfo settings so kUP5 (Ctrl-Up etc) are the adjusted versions, and disable smkx/rmkx so tmux doesn't change the mode. For example with this line in .tmux.conf (assuming you have TERM set to xterm):

set -g terminal-overrides "xterm*:kLFT5=\eOD:kRIT5=\eOC:kUP5=\eOA:kDN5=\eOB:smkx@:rmkx@"

Note that this will only work in tmux 1.2 and above.

http://stuff.mit.edu/afs/athena/project/bsd/src/tmux-1.3/FAQ