1. Overview

tmux, short for Terminal Multiplexer, is a great command line tool that lets us create, access, and control multiple terminal sessions from a single screen. One useful feature of tmux is that it operates through a series of keybindings, which are essentially keyboard shortcuts that trigger various commands within tmux.

By default, the prefix for these commands is Ctrl+B. After pressing the prefix, we can input a valid key to perform a specific action. Overall, tmux improves our workflow without relying on the trackpad or mouse.

In this tutorial, we’ll discuss valid key bindings for tmux and how to check unbound keys. We’ll also look at the types of keybindings available in tmux.

2. What Are Key Bindings in tmux?

*Key bindings in tmux are a set of predefined shortcuts that allow us to control tmux‘s behavior and execute commands within the tmux environment*. We can manage tmux sessions without having to type out full commands using these bounded predefined keyboard shortcuts.

Furthermore, we can modify key bindings in tmux through the bind-key and unbind-key commands. Moreover, each binding associates a specific key table, and tmux comes with four pre-established key tables:

  • root table holds the key bindings for individual key presses, regardless of the prefix key
  • prefix table is for the bindings of keys that are pressed following the prefix key
  • copy-mode table is designated for the bindings of keys that are used in copy mode, following the style of emacs keys
  • copy-mode-vi table is for the bindings of keys that are used in copy mode, but with the style of vi keys

Furthermore, we can use these tables to organize the key bindings based on their function and the mode in which they’re used.

3. Check Valid Keys on the Manual Page for tmux

In most cases, we can check all the valid keys for tmux using its manual page. To access the tmux manual page, we need to type the man tmux command in the terminal:

$ man tmux

This will display the manual page, where we can find the Default Key Bindings section, which lists all the default key bindings for tmux.

The tmux program lets us link almost any key on the keyboard, with or without a prefix key. We can use keys directly, like the letters A to Z. For control keys, we need to add C- or ^ before the key, and for Alt keys, we can use M-.

Additionally, tmux also understands special keys like the arrows Up, Down, Left, and Right.

4. List Current Bindings

There are several methods available that we can use to get the current key bindings for tmux. Moreover, we can get the current bindings either inside the tmux session or even when not inside the tmux session.

4.1. Using tmux list-keys

To see all current key bindings, including custom and plugin-added bindings, we can use tmux list-keys or tmux lsk inside a tmux session:

$ tmux list-keys
bind-key -T copy-mode C-Space send-keys -X begin-selection
bind-key -T copy-mode C-a send-keys -X start-of-line
bind-key -T copy-mode C-b send-keys -X cursor-left
bind-key -T copy-mode C-c send-keys -X cancel
bind-key -T copy-mode C-e send-keys -X end-of-line
bind-key -T copy-mode C-f send-keys -X cursor-right
bind-key -T copy-mode C-g send-keys -X clear-selection
bind-key -T copy-mode C-k send-keys -X copy-pipe-end-of-line-and-cancel
...

This will show all the available bound keys, which can help us to avoid conflicts when creating new bindings.

Moreover, we can also see the currently bound keys directly within our tmux session. We can press the prefix key (usually Ctrl+B), followed by the question mark (?) key. This acts as a shortcut for the tmux list-keys command and will bring up the list of all key bindings available within a tmux session.

Furthermore, we can list the keys of a specific key binding table using the tmux list-keys command with the -T flag followed by the name of the key table:

$ tmux list-keys -T prefix
$ tmux list-keys -T root
$ tmux list-keys -T copy-mode
$ tmux list-keys -T copy-mode-vi

Here, each of these commands will list the keys bound in the specified table, allowing us to see the key bindings that are active in different modes within tmux.

4.2. tmux Configuration File

Another way to get the current binding keys is the tmux configuration file, which is located at ~/.tmux.conf. Moreover, this file contains a set of defined tmux commands that we can execute whenever we start tmux. By using this file, we can define custom commands to control various aspects of tmux.

The bind-key command inside the .tmux.conf file allows us to define new key bindings or change existing ones. Similarly, the unbind-key command can remove a key binding.

Furthermore, we can edit this file to redefine the prefix key or define a new key binding for it:

# Use C-s (control and s key) as prefix key
unbind C-b
set -g prefix C-s

After saving the file, let’s reload the configuration:

$ tmux source-file ~/.tmux.conf

If the configuration file doesn’t exist, we can create an empty one using the touch command.

5. List the Unbound Keys in tmux

Unfortunately, tmux doesn’t provide a built-in way to list unbound keys directly. However, we can use some workaround methods to get the list of unbound keys.

Additionally, we can compare the list of all supported keys with the list of currently bound keys. We can do this by using tmux list-keys along with other commands like awk and comm to filter out the bound keys, giving us the unbound ones.

First, let’s get a list of all possible keys that tmux supports. For this, we can use the tmux man page and copy all those keys inside a text file.

After that, we need to use the tmux list-keys command to get a list of all the keys that are currently bound. Next, we can pipe the output of tmux list-keys into awk to extract the first four columns. Lastly, redirect the output of awk into a text file.

Let’s combine them all and execute it in a terminal:

$ tmux list-keys | awk '{print $1, $2, $3, $4}' > tmux_keys.txt

Now, we can find the unbound keys by comparing the valid and bound key lists. We can use any text processing command line tools like comm to compare this list with the list we get from the man page to find the unbound keys.

Moreover, manually extracting the valid keys from the tmux man page and then comparing them with the currently bound keys can be tedious.

Another easy approach is to print the currently bound keys using the tmux list-keys command inside the text file. After that, we can use the find option of any text editor to search for the key that we need to bind. If the key is already present, we see that it’s already bound and unavailable.

6. Conclusion

In this article, we talked about the tmux valid keys.

We started with a basic tmux introduction. Then, we looked at what key bindings are in tmux. Further, we discussed all four types of tmux key bindings. We also learned about how to unbind and bind a new key in the tmux configuration file.

In the end, we explored a different way to identify unbound keys in tmux.