Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I'd like to use the numeric keypad to select windows in tmux. Anybody do this?

share|improve this question
    
Try reading the man pages and look at the key binding commands in tmux –  Stu Wilson Jan 27 '12 at 22:20
3  
This is technically on topic here, but you may be more likely to get an answer on unix.stackexchange.com . –  Nathan Greenstein Jan 27 '12 at 23:11

2 Answers 2

If you have numlock enabled, the keypad sends the same input to the terminal as the number keys above the qwerty letters, so there's no way to specify the keypad specifically. You can try to map the non-numlocked inputs from the keypad, but I think that's specific to your keyboard and terminal.

To map a key without requiring Prefix, use bind-key -n key command. The -n stands for "normal mode". So the commands that you likely want to add are:

bind-key -n 0 select-window -t 0
bind-key -n 1 select-window -t 1
bind-key -n 2 select-window -t 2
bind-key -n 3 select-window -t 3
bind-key -n 4 select-window -t 4
bind-key -n 5 select-window -t 5
bind-key -n 6 select-window -t 6
bind-key -n 7 select-window -t 7
bind-key -n 8 select-window -t 8
bind-key -n 9 select-window -t 9
share|improve this answer
    
Thanks. I used to do with with Linux and emacs way back when. Maybe I'll figure it out someday. –  chrismealy Nov 29 '12 at 22:26
    
Could you explain a little more about what you're trying to do? I'd be happy to help you figure it out. –  Anthony DiSanti Nov 29 '12 at 23:10
    
The idea is that I could use the numbers on the numeric keypad to switch between tmux windows, without doing the tmux prefix command first. –  chrismealy Nov 30 '12 at 2:55

If your terminal emulator outputs certain codes for the keypad keys, then these commands (e.g. in your .tmux.conf) will bind Keypad 0Keypad 9 to work exactly like prefix+0prefix+9:

bind-key -n KP0 select-window -t :0
bind-key -n KP1 select-window -t :1
bind-key -n KP2 select-window -t :2
bind-key -n KP3 select-window -t :3
bind-key -n KP4 select-window -t :4
bind-key -n KP5 select-window -t :5
bind-key -n KP6 select-window -t :6
bind-key -n KP7 select-window -t :7
bind-key -n KP8 select-window -t :8
bind-key -n KP9 select-window -t :9

The -n means that you do not have to use the prefix key; the key names (KPx) do not seem to be in the documentation, but you can find them in the source in the file key-string.c. They values your terminal must send seem to be hard-coded: see tty-keys.c; TTYKEY_RAW means that terminfo is not used, and there are no other entries for the KEYC_KP* keys without TTYKEY_RAW (where terminfo might be consulted; the problem here is that terminfo support for the numeric keypad seems to be incomplete).

You can check whether your terminal emulator sends special codes for the keys by running this outside tmux:

tput smkx;cat -v;tput rmkx

(use Control+c to end the cat instance)

You should probably see something like this for KP0–KP9:

^[Op^[Oq^[Or^[Os^[Ot^[Ou^[Ov^[Ow^[Ox^[Oy

This works for me by default in iTerm2 (Build 1.0.0.20120724), but in Terminal (Version 2.3 (309); from OS X 10.8.2) I had to enable Allow VT100 application keypad mode for a profile (Terminal menu > Preferences…; Settings tab > select a profile > Advanced tab; check Allow VT100 application keypad mode under Emulation).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.