Using Ctrl+[0-9] to cycle between windows using tmux

Several of the Control+digit keystrokes generate fairly standardized sequences, but not all of them do.

Here is what I found in the xterm that I had handy:

C-1: 1  (i.e. not different form a plain 1 keystroke)
C-2: ^@
C-3: ^[
C-4: ^\
C-5: ^]
C-6: ^^
C-7: ^_
C-8: ^?
C-9: 9  (i.e. plain 9)
C-0: 0  (i.e. plain 0)

The same sequences are generated in iTerm 2 (although this is highly configurable).

If your terminal emulator generates similar sequences, then you could bind most of them (though you need to use the standard, non-numeric “names” for the keys, e.g. C-@ or ^@, et cetera). You will have to find a way to configure your terminal to send some kind of sequence for any keystrokes that do not already send something different from the unmodified key (i.e. like 1, 9, and 0 above).

However, binding these keys without a Prefix (bind -n …) will probably break lots of stuff. Specifically, ^[ is the Escape character (used in almost all terminal control sequences), ^? is usually the Delete character, ^@ (as C-Space) is commonly used in Emacs(-style) editing, et cetera.

Probably a better approach is to configure your terminal to send the xterm-style “modifyOtherKeys” sequences that tmux 1.8 recognizes (if your xterm supports this, tmux automatically asks for this to happen):

C-1: ^[[27;5;49~
C-2: ^[[27;5;50~
C-3: ^[[27;5;51~
C-4: ^[[27;5;52~
C-5: ^[[27;5;53~
C-6: ^[[27;5;54~
C-7: ^[[27;5;55~
C-8: ^[[27;5;56~
C-9: ^[[27;5;57~
C-0: ^[[27;5;48~

The tmux names for these keys are exactly C-0, et cetera.

Note: These key names and sequences are not recognized by tmux versions older than 1.8.

You would bind them like this (in your .tmux.conf):

bind-key -n C-0 select-window -t :0
bind-key -n C-1 select-window -t :1
bind-key -n C-2 select-window -t :2
bind-key -n C-3 select-window -t :3
bind-key -n C-4 select-window -t :4
bind-key -n C-5 select-window -t :5
bind-key -n C-6 select-window -t :6
bind-key -n C-7 select-window -t :7
bind-key -n C-8 select-window -t :8
bind-key -n C-9 select-window -t :9

@ChrisJohnsen answer is perfect, however some people might want some help on how to setup Iterm 2 keys in order to achieve this behavior.

First, go to "Iterm2 -> Preferences -> Profiles -> Keys" as in:

Iterm profile configuration

and then click on + symbol to add preset when some Ctrl+Number is not on the list (the format on the list will be ^number), as it is the case for the ^1, which is not available on the default list.

Press Ctrl+1 when selecting the keyboard shortcut and select "send escape sequence" as action. Then, add Chris Johnsen's escape sequences without the ^[, which will be added by the iterm2 action:

enter image description here

Later, repeat this procedure for all other control keys, editing those already existent.