110

In both zsh and bash, ctrl+arrows allows me to move the position I'm typing at by whole word, but this does not work in tmux, which is a problem as I'm currently launching it automatically every time I open a shell.

How can I fix this?

Victor Yarema
  • 378
  • 4
  • 7
Llamageddon
  • 1,507
  • 2
  • 11
  • 14

5 Answers5

147
  1. Edit your ~/.tmux.conf and add lines:

    set-window-option -g xterm-keys on
    
  2. If you don’t want to make it permanent just yet, do:

    C-b :set-window-option xterm-keys on
    
  3. Reload your config in tmux by doing:

    C-b :source-file ~/.tmux.conf
    

More information here:

phuclv
  • 26,555
  • 15
  • 113
  • 235
sgzmd
  • 1,586
  • 1
  • 10
  • 4
  • 3
    Strange: This works for me only if I reload the ~/.tmux.conf file from tmux or set the action in the :-prompt of tmux, not initially when I open tmux. Any ideas what might be the problem there? – AME Nov 28 '13 at 18:06
  • @AME close all tmux sessions then try again. – Nathan Sep 07 '15 at 06:13
  • 1
    If reload config doesn't fix the problem (this is the case for me), try a new session. Maybe you need to kill the current session and create a new one. Another option to make it take effect in a pane (not a session) is C-b: respawn-pane -k – fstang Mar 16 '16 at 21:28
  • This worked for me, mostly. I wonder why it's not on by default? – inetknght Jan 16 '17 at 21:58
  • 1
    Killing the session, or whatever `set-window-option -g xterm-keys on` still doesn't do anything in my case. – noraj Nov 12 '17 at 23:57
  • 1
    press `C-b` then `kill-server` or `tmux kill-server` before testing the result – Fabrizio Bertoglio Jan 24 '20 at 09:56
  • This didnt work for me. when sshing into a remote tmux session meta left/right prints ;3D ;3C – SFbay007 Apr 17 '20 at 21:57
12
set-window-option -g xterm-keys on

Got me some of the way there and gave me Ctrl-Left/Right on the console, but it was still responding differently in vim.

Unbinding the keys didn't seem to help.

It turned out that at some point I had set my default terminal to screen (set-option -g default-terminal "screen" in .tmux.conf)

Changing this to the following gave me Ctrl-Left/Right in everything else:

set-option -g default-terminal "xterm-256color"

Hope that helps somebody.

phuclv
  • 26,555
  • 15
  • 113
  • 235
Kieran Moore
  • 221
  • 2
  • 2
4

For me, the keys were not being bound correctly, because the system preferences in High Sierra were set to being used by Mission Control. Unchecking these then allowed the correct bindings to work in iTerm2 and Tmux

System Preferences

Unchecking all of the items referencing the control key, allowed the bindings to work properly

JonathanDavidArndt
  • 1,344
  • 7
  • 25
  • 42
Andrew
  • 589
  • 3
  • 6
3

For msys2/Cygwin/mintty:

Add below to ~/.inputrc.

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

Reload would make tmux work correctly.

Mithril
  • 937
  • 3
  • 12
  • 25
3

I'm not sure, but this might be because tmux by default binds C-<up/down/left/right> to shift the focus onto the pane above/below/left of/right of the currently focused pane. If you don't use panes often, you might not have noticed this feature. If this is what the problem is, you can unbind those keys by saying:

unbind C-Left
unbind C-Right

That might be enough on it's own, or you might need to manually bind them again to what you want them to do, via:

bind -n C-Left <the action you want>
bind -n C-Right <other action you want>
jake-low
  • 382
  • 3
  • 8
  • 1
    It should be enough on it's own, if it isn't grabbed by tmux, it should pass onto the shell. – Rob Dec 14 '11 at 17:37