This is possible if and only if the terminal sends different escape sequences for Ctrl+Left vs Left. This is not the case by default on the Linux console (at least on my machine). You can make it so by modifying the keymap. The exact file to modify may depend on your distribution; on Debian lenny, the file to modify is /etc/console/boottime.kmap.gz
. You need lines like
control keycode 105 = F100
string F100 = "\033O5D"
control keycode 106 = F101
string F101 = "\033O5C"
You might as well choose the same escape sequences as your X terminal emulator. To find out what the control sequence is, type Ctrl+V Ctrl+Left in a shell; this inserts (on my machine) ^[O5D
where ^[
is an escape character. In the keymap file, \033
represents an escape character.
Configuring the application in the terminal to decode the escape sequence is a separate problem, .
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):
There are others, such as
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:
Best Answer
Gnome-terminal (more properly VTE) imitates some version of xterm's escape sequences. How closely it does this, depends on the version of VTE.
The relevant xterm documentation is in the PC-Style Function Keys section of XTerm Control Sequences.
What you are looking for is a string like
\e[1;5D
(for control left-arrow), where the5
denotes the control modifier.In ncurses, you can see these strings using
infocmp -x
, as the values forkUP5
,kDN5
,kLFT5
andkRIT5
. For example: