How to run a tmux command from inside a session?

By Romain Dorgueil

Short answer

Press prefix :, then type a tmux command without the leading tmux word:

split-window -h
resize-pane -D 10
source-file ~/.tmux.conf

The command runs against the server you are attached to, right now.

Details

prefix : opens the command prompt (command-prompt), a one-line input at the bottom of the screen. It is the interactive twin of the shell CLI: the same commands, the same flags, minus the tmux word in front. Anything you would run as tmux split-window -h becomes split-window -h here.

Two moments where it earns its place. First, trying something once before you commit to it: run resize-pane -D 10 or a new set from the prompt, see the effect, then decide whether it belongs in ~/.tmux.conf. Second, reaching a command that has no default key binding, without dropping to a shell.

A template can prompt for input before it runs. command-prompt -p "new name:" "rename-window '%%'" shows the prompt new name:, then substitutes whatever you type for %%. With several -p prompts, use %1, %2 and so on to place each answer. That is how the built-in bindings for renaming and finding are wired, and how you can build your own.

Verified on tmux 3.2a.

Related