# tmux bind-key

Source: https://libtmux.org/en/tmux/latest/manual/bind-key/

> Bind key key to command.

Bind key key to command.

## Syntax

```tmux-usage
tmux bind-key [-nr] [-T key-table] [-N note] key [command [argument ...]]
```

Alias: `bind`.

## Behavior

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`](https://libtmux.org/en/tmux/latest/manual/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`](https://libtmux.org/en/tmux/latest/manual/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`](https://libtmux.org/en/tmux/latest/manual/switch-client/) `-T` command used to switch to them from a key binding. The `-r` flag indicates this key may repeat, see the `initial-repeat-time` and `repeat-time` options. `-N` attaches a note to the key (shown with [`list-keys`](https://libtmux.org/en/tmux/latest/manual/list-keys/) `-N`), which can be cleared by passing an empty string. The `-r` and `-N` flags can be used without `command` to alter an existing binding.

To view the default bindings and possible commands, see the [`list-keys`](https://libtmux.org/en/tmux/latest/manual/list-keys/) command.

## C implementation

Internal declarations in tmux 3.7c:

* [`cmd_bind_key_entry`](https://libtmux.org/en/tmux/latest/reference/c-variable-cmd_bind_key_entry/)
* [`cmd_bind_key_exec`](https://libtmux.org/en/tmux/latest/reference/c-function-cmd-bind-key-c-cmd_bind_key_exec/)

## Use from a library

Each API describes its own defaults, errors and execution model.

* [Python](https://libtmux.org/en/py/latest/reference/libtmux-server-bind_key/)
* [Rust](https://libtmux.org/en/rs/latest/reference/server-server-bind_key/)
* [Go](https://libtmux.org/en/go/latest/reference/tmux-server-bindkey/)
* [Java](https://libtmux.org/en/java/latest/reference/io-github-libtmux-keys-keys-bind/)
* [C#](https://libtmux.org/en/csharp/latest/reference/libtmux-tmuxkeys-bindasync/)
* [C++](https://libtmux.org/en/cxx/latest/reference/libtmux-server-bind_key/)

tmux sources and license

Syntax comes from `tmux 3.7c list-commands`. See the [global options](https://libtmux.org/en/tmux/latest/manual/full/#DESCRIPTION) for sockets and configuration, and [command syntax and targets](https://libtmux.org/en/tmux/latest/manual/full/#COMMANDS).

Behavior is taken from the [tmux 3.7c manual](https://github.com/tmux/tmux/blob/79072dd1a9f5fb437a5859e362a496fd57ec0981/tmux.1).

[Command declaration](https://github.com/tmux/tmux/blob/79072dd1a9f5fb437a5859e362a496fd57ec0981/cmd-bind-key.c#L36)

```
Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
```
