8

In tmux to select a window, the default behavior is C-b <number>. I would like to avoid the prefix by using alt+ for a faster selecting.

I did it for the next and previous window, and it works:

 bind -n M-n select-window -n
 bind -n M-p select-window -p

For the selection by id, I did the same, but it does not work:

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

Is there an easy way to make it working?

6
  • I find tmux to be flummoxing.
    – wogsland
    Commented Mar 19, 2017 at 15:28
  • Your configuration works for me where Alt+key combinations usually work. For example they work in gnome-terminal, but in xterm not. So in xterm I have to use Esc, key sequence instead, not only in tmux, but for example in mc too. I would say, your tmux configuration is fine, the host terminal messes things up.
    – manatwork
    Commented Mar 21, 2017 at 17:07
  • For me it does not work in gnome-terminal neither in xterm. I have to use Esc, key to make it works for about the half of the keys.
    – Phantom
    Commented Mar 24, 2017 at 20:16
  • @Phantom It works for me in MobaXterm.
    – shahensha
    Commented Mar 20, 2019 at 13:37
  • The bindings work for me in Tmux 2.6 in Konsole 17.12.3. Commented Oct 7, 2020 at 19:05

2 Answers 2

1

You can create shortcuts to cycle through windows using the bind-key command.

So, to select windows using Alt+<number>, you can do:

bind-key -n M-1 selectw -t 1
bind-key -n M-2 selectw -t 2
bind-key -n M-3 selectw -t 3
(...)
1
  • worked for me (using kitty on macos) Commented Sep 21, 2023 at 19:07
0

As you can see here tmux does not support numeric characters to keybinding.

Because I'm using tmux with iTerm I'd a workaround:

  • On iTerm -> preferences -> Keys -> Key binding: I did bind the key+number to a specific char, e.g.: C-0 -> 🀱 ; C-1 -> 🀲 ; etc
  • on .tmux.conf I do use that char: bind·-n·🀲·…

To other terminal clients, I guess there is an option to map the keys in the same way, so it is just a matter to find how to map the keys.

2
  • Thanks, I didn't know that tmux does not allow numeric characters for keybinding. But from what I saw, iTerm is only for Mac, so it won't be useful as I'm under Linux
    – Phantom
    Commented May 11, 2020 at 11:21
  • I see, under Linux, you have even more options… To use the same workaround you can use konsole it does have the remap functionality in the same way as iterm… I did a VM to try it and it works, look: imgur.com/gallery/0u1bnkP Commented May 11, 2020 at 17:42

You must log in to answer this question.

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