# tmux_key:bind/4

- **Package:** libtmux_erlang
- **Language:** Erlang
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-erlang/blob/d1b6308440cf9eb8f6647e7ae434bce60e849368/apps/libtmux_erlang/src/tmux_key.erl#L70
- **Page:** https://libtmux.org/en/erlang/latest/reference/tmux_key-bind-4/

```
bind(Server, Key0, Commands, Options)
-spec bind(tmux_server:t(),
           key(),
           tmux_command:t() | [tmux_command:t(), ...],
           bind_options()) ->
              {ok, tmux_operation:completed()} |
              {error, tmux_operation:failure()}.
```

Register or replace one binding with validated command values. Commands can be one value or a flat nonempty list; `tmux_command:to_config/1` applies the aggregate count and byte bounds. Options follow `t:bind_options/0`. Arguments, table names and notes are literal bytes at registration; stored commands still interpret their values and formats when a client executes them.

Performs I/O. tmux parses the commands before replacing an existing binding.
The result confirms registration, while effects of future key presses need
their own acknowledgement. Replacement resets the old repeat flag and note
using the supplied options. Errors preserve backend diagnostics and unknown
outcomes; there is no rollback or automatic retry.

## Parameters

- `Server` (`tmux_server:t()`)
- `Key0` (`key()`)
- `Commands` (`tmux_command:t() | [tmux_command:t(), ...]`)
- `Options` (`bind_options()`)

## tmux command

The tmux commands behind `bind/4`.

- [`bind-key`](/en/tmux/latest/manual/bind-key/)

## tmux C API

The C declarations in tmux that implement these commands.

- [`cmd_bind_key_entry`](/en/tmux/latest/reference/c-variable-cmd_bind_key_entry/) (attribute)
- [`cmd_bind_key_exec`](/en/tmux/latest/reference/c-function-cmd-bind-key-c-cmd_bind_key_exec/) (function)

## Guides

Pages that discuss `bind/4`.

- [Install application keybindings](/en/erlang/latest/guides/keys/)
