Get Ctrl+Arrow to work under tmux+urxvt

I have tmux command key as C-a. C-Left/C-Right to jump between words (or whatever it is called) works just fine in urxvt alone, but under urxvt/tmux it'll print '5D' and '5C' for Left/Right respectively. How do I configure tmux so word skipping works (either with on X with urxvt or in a tty)?


Solution 1:

Add this to your .Xdefaults

URxvt.keysym.Control-Up:     \033[1;5A
URxvt.keysym.Control-Down:   \033[1;5B
URxvt.keysym.Control-Left:   \033[1;5D
URxvt.keysym.Control-Right:  \033[1;5C

URxvt will now send the same escape sequences as XTerm.

This will make sure that word-jumping will even work when you are connected to a remote maching with its own .inputrc using SSH.

For making urxvt act more like xterm see http://www.netswarm.net/misc/urxvt-xtermcompat.txt

Solution 2:

Excerpt from Ctrl-left and Ctrl-right in bash and Emacs:

Sometimes the small things make a big difference. I noticed that the control-left 
and control-right keys weren’t working in bash or Emacs on my FreeBSD box 
accessed over X11.app on OS X. Easily fixed.

.inputrc

    "\e[1;5C": forward-word     # Ctrl+right  => forward word
    "\e[1;5D": backward-word    # Ctrl+left   => backward word

.emacs

    (global-set-key "\M-[1;5C"    'forward-word)  ; Ctrl+right   => forward word
    (global-set-key "\M-[1;5D"    'backward-word) ; Ctrl+left    => backward word
  • I guess you'd need to do that in each programs and change their key bindings.
  • I don't know why tmux mangles the keystrokes going through though.

Solution 3:

If you use zsh, add this to your ~/.zshrc

bindkey "5C" forward-word
bindkey "5D" backward-word

Got it from http://clock.co.uk/blog/zsh-ctrl-left-arrow-outputting-5d