Problem using Ctrl+Arrow keys in Vim when using Byobu with tmux

The problem is twofold. First, tmux by default converts the control-arrow keys from one type of escape sequence to another. So special keys such as controlleft are sent to vim without the modifier, e.g., left. If you use cat -v to see the different escape sequences, you might see something like this

^[OD

versus this (outside tmux):

^[[1;5D

The line

set-window-option -g xterm-keys on

fixes that aspect. The other part is that tmux by default uses the terminal description for screen. That terminal description does not describe the control-arrow keys. These entries from the terminal database would be the most appropriate for VTE (gnome-terminal):

  • screen.vte
  • screen.vte-256color

There are others, such as

  • screen.xterm-new
  • screen.xterm-256color

which would be automatically selected when running in screen if the corresponding TERM outside were vte, vte-256color, etc. tmux does not do this automatic-selection; you have to modify its configuration file.

By the way, there is no "screen.xterm" entry because it would interfere with some usages of screen. There is no conflict with TERM=xterm-new.

If you have a default (minimal) terminal database such as ncurses-base in Debian, you might not have those. More common would be xterm-256color, which is close enough to use with vim and tmux.

For example, if I add this to my .tmux.conf file, it behaves as you expect in vim:

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

Further reading:

  • XTERM Extensions (terminal database)
  • vim: how to specify arrow keys
  • How can I see what my keyboard sends?

From here you can unbind the key combination in byobu:

Create a file ~/.byobu/.tmux.conf with (or add if the file exists):

set-window-option -g xterm-keys on

Then add the following to ~/.byobu/keybindings.tmux:

unbind-key -n C-Left
unbind-key -n C-Right

Tags:

Vim

Tmux

Byobu