112

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?

phuclv
  • 30,396
  • 15
  • 136
  • 260
Llamageddon
  • 1,577

5 Answers5

151
  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
  • 30,396
  • 15
  • 136
  • 260
sgzmd
  • 1,626
14
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
  • 30,396
  • 15
  • 136
  • 260
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

Andrew
  • 647
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

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