# tmux command-prompt

Source: https://libtmux.org/en/tmux/3.2a/manual/command-prompt/

> Open the command prompt in a client.

Open the command prompt in a client.

## Syntax

```tmux-usage
tmux command-prompt [-1kiNTW] [-I inputs] [-p prompts] [-t target-client] [template]
```

## Behavior

Open the command prompt in a client. This may be used from inside `tmux` to execute commands interactively.

If `template` is specified, it is used as the command. If present, `-I` is a comma-separated list of the initial text for each prompt. If `-p` is given, `prompts` is a comma-separated list of prompts which are displayed in order; otherwise a single prompt is displayed, constructed from `template` if it is present, or ‘`:`’ if not.

Before the command is executed, the first occurrence of the string ‘`%%`’ and all occurrences of ‘`%1`’ are replaced by the response to the first prompt, all ‘`%2`’ are replaced with the response to the second prompt, and so on for further prompts. Up to nine prompt responses may be replaced (‘`%1`’ to ‘`%9`’). ‘`%%%`’ is like ‘`%%`’ but any quotation marks are escaped.

`-1` makes the prompt only accept one key press, in this case the resulting input is a single character. `-k` is like `-1` but the key press is translated to a key name. `-N` makes the prompt only accept numeric key presses. `-i` executes the command every time the prompt input changes instead of when the user exits the command prompt. `-T` tells `tmux` that the prompt is for a target which affects what completions are offered when *Tab* is pressed; `-W` is similar but indicates the prompt is for a window.

The following keys have a special meaning in the command prompt, depending on the value of the `status-keys` option:

|                                                                                               |                                                              |                                                                    |
| --------------------------------------------------------------------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------------ |
| [**Function**](https://libtmux.org/en/tmux/3.2a/manual/full/#Function~4)                      | [**vi**](https://libtmux.org/en/tmux/3.2a/manual/full/#vi~2) | [**emacs**](https://libtmux.org/en/tmux/3.2a/manual/full/#emacs~2) |
| [`Cancel command prompt`](https://libtmux.org/en/tmux/3.2a/manual/full/#Cancel)               | q                                                            | Escape                                                             |
| [`Delete from cursor to start of word`](https://libtmux.org/en/tmux/3.2a/manual/full/#Delete) |                                                              | C-w                                                                |
| [`Delete entire command`](https://libtmux.org/en/tmux/3.2a/manual/full/#Delete~2)             | d                                                            | C-u                                                                |
| [`Delete from cursor to end`](https://libtmux.org/en/tmux/3.2a/manual/full/#Delete~3)         | D                                                            | C-k                                                                |
| [`Execute command`](https://libtmux.org/en/tmux/3.2a/manual/full/#Execute)                    | Enter                                                        | Enter                                                              |
| [`Get next command from history`](https://libtmux.org/en/tmux/3.2a/manual/full/#Get)          |                                                              | Down                                                               |
| [`Get previous command from history`](https://libtmux.org/en/tmux/3.2a/manual/full/#Get~2)    |                                                              | Up                                                                 |
| [`Insert top paste buffer`](https://libtmux.org/en/tmux/3.2a/manual/full/#Insert)             | p                                                            | C-y                                                                |
| [`Look for completions`](https://libtmux.org/en/tmux/3.2a/manual/full/#Look)                  | Tab                                                          | Tab                                                                |
| [`Move cursor left`](https://libtmux.org/en/tmux/3.2a/manual/full/#Move)                      | h                                                            | Left                                                               |
| [`Move cursor right`](https://libtmux.org/en/tmux/3.2a/manual/full/#Move~2)                   | l                                                            | Right                                                              |
| [`Move cursor to end`](https://libtmux.org/en/tmux/3.2a/manual/full/#Move~3)                  | $                                                            | C-e                                                                |
| [`Move cursor to next word`](https://libtmux.org/en/tmux/3.2a/manual/full/#Move~4)            | w                                                            | M-f                                                                |
| [`Move cursor to previous word`](https://libtmux.org/en/tmux/3.2a/manual/full/#Move~5)        | b                                                            | M-b                                                                |
| [`Move cursor to start`](https://libtmux.org/en/tmux/3.2a/manual/full/#Move~6)                | 0                                                            | C-a                                                                |
| [`Transpose characters`](https://libtmux.org/en/tmux/3.2a/manual/full/#Transpose)             |                                                              | C-t                                                                |

## C implementation

Internal declarations in tmux 3.2a:

* [`cmd_command_prompt_entry`](https://libtmux.org/en/tmux/3.2a/reference/c-variable-cmd_command_prompt_entry/)
* [`cmd_command_prompt_exec`](https://libtmux.org/en/tmux/3.2a/reference/c-function-cmd-command-prompt-c-cmd_command_prompt_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-command_prompt/)
* [Rust](https://libtmux.org/en/rs/latest/reference/server-server-command_prompt/)
* [Go](https://libtmux.org/en/go/latest/reference/tmux-server-commandprompt/)
* [C#](https://libtmux.org/en/csharp/latest/reference/libtmux-server-showcommandpromptasync/)

tmux sources and license

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

Behavior is taken from the [tmux 3.2a manual](https://github.com/tmux/tmux/blob/85893888497c5077979bc7557fb970ee5e3d13d9/tmux.1).

[Command declaration](https://github.com/tmux/tmux/blob/85893888497c5077979bc7557fb970ee5e3d13d9/cmd-command-prompt.c#L40)

```
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.
```
