97

Tmux by default comes with the following keybinding to quickly switch between windows numbered 0 to 9:

C-b + 0-9

With a couple of dozen different project folders, a few ssh sessions and other goodies in my tmux, I seem to always spill over the 10 windows I can quickly access, and I would love to figure out a quick way to switch to windows numbered 10 or higher. Right now I have to manually type out something along these lines in the tmux prompt:

swap-window -t 12

Which is quite time-consuming.

Has anyone figured out a solid shortcut that helps you quickly access windows 10 and higher? I know weechat solved this problem with the two shorcuts:

Alt + 0-9
Alt+j followed by \d{2}

Can anything along those lines be accomplished with tmux?

1

2 Answers 2

152

There are a few easy ways to do it.

  • Use C-b ' to select the window index.

  • Use C-b w to get an interactive index to choose from (0-9a-z).

  • Add bindings to cycle through quickly in tmux.conf

    bind -r C-h select-window -t :-
    bind -r C-l select-window -t :+

The -r in the last one lets you repeat the key without having to repeat C-b. Typically the second one is the least number of keystrokes.

3
  • 5
    The first two commands are exactly what I was looking for, thank you Jason!
    – glitch
    Jun 5, 2014 at 20:01
  • 1
    Ah. I've fatfingered C-b w a bunch accidentally and have been spooked. Now I finally know what it's for.
    – ijoseph
    Nov 3, 2020 at 19:46
  • Would be great if the C-b ' still showed the window index on the line above instead of covering it up when it asked for index ..
    – ikwyl6
    Aug 13, 2023 at 22:26
7

You can use switch-client -T<keytablename> to configure a sequence of keys to directly access high-number windows.

For example I use this configuration to jump to windows 10-19 with Ctrl-b + - + [0-9]:

bind - switch-client -Tabove9
bind -Tabove9 0 select-window -t:10
bind -Tabove9 1 select-window -t:11
bind -Tabove9 2 select-window -t:12
bind -Tabove9 3 select-window -t:13
bind -Tabove9 4 select-window -t:14
bind -Tabove9 5 select-window -t:15
bind -Tabove9 6 select-window -t:16
bind -Tabove9 7 select-window -t:17
bind -Tabove9 8 select-window -t:18
bind -Tabove9 9 select-window -t:19

Detailed explanation:

As explained in the tmux manpage, switch-client can be used to set the current key table to create key combinations:

switch-client [-ElnprZ] [-c target-client] [-t target-session] [-T key-table]

...

-T sets the client's key table; the next key from the client will be interpreted from key-table. This may be used to configure multiple prefix keys, or to bind commands to sequences of keys. For example, to make typing ‘abc’ run the list-keys command:

               bind-key -Ttable2 c list-keys
               bind-key -Ttable1 b switch-client -Ttable2
               bind-key -Troot   a switch-client -Ttable1

So in my example I configured the - key to switch to a custom table named above9 and then configured keys 0 to 9 in that table to switch to windows 10 to 19.

This is equivalent to GNU screen's bind -c <class> (that's where I come from)

1
  • Love it. Did something like it just now, but using "+" instead of "-" and I also switched numbering to start from 1 (base-index FTW :D). So, 1-0 do 1 to 10, and 11 to 20 are <prefix> + 1 to 0. (And 21 to 30 are prefix + + 1-10 :D) Mar 28, 2023 at 23:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .