12

My Problem

tmux key bindings require two separate key hits to enter a command. The first is called a prefix, and set to control+a. The second key performs the actual command, for example:

  • c create window
  • w list windows
  • n next window
  • w previous window
  • f find window
  • , name window
  • & kill window

The problem is that two consecutive key combinations are cumbersome and slow. Most other tabbed UIs - from Chrome to Vim - enable tab switching with a single combination.

What Have I Tried

  • STFW
  • Played with bind-key and send-keys, for example bind-key C-c send-keys C-a n

My Question

How can I run specific tmux commands, like "next window" or "create window", with a single key combination?

2 Answers 2

7

Solution

I have something like this in my ~/.tmux.conf file:

bind -n C-h select-pane -L

Maps <Ctrl>-h to select pane on the left.

Manual reference for the -n argument

bind-key [-nr] [-T key-table] key command [arguments]
    (alias: bind)
Bind key key to command.  Keys are bound in a key table.  By default (without -T), the key is
bound in the prefix key table.  This table is used for keys pressed after the prefix key (for
example, by default `c' is bound to new-window in the prefix table, so `C-b c' creates a new
window).  The root table is used for keys pressed without the prefix key: binding `c' to
new-window in the root table (not recommended) means a plain `c' will create a new window.
-n is an alias for -T root.  Keys may also be bound in custom key tables and the
switch-client -T command used to switch to them from a key binding.  The -r flag indicates
this key may repeat, see the repeat-time option.

To view the default bindings and possible commands, see the list-keys command.
1
  • For some strange reason, it does not work for me. Has anyone verified this in Linux/Terminator/Zsh? May 14, 2021 at 11:32
1

Here's a solution for selecting windows. Use bindings that feel right to you. The accepted answer runs into the problem, using C-h, where you might pair it with C-l, but ctrl+l is often used in shells to clear the screen.

bind-key -n C-S-Left previous-window
bind-key -n C-S-Right next-window

See also select-window in man tmux for alternative ways to change windows.

You must log in to answer this question.

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