Command Mode: The:Prompt and What Sits Behind Every Key Binding
Opening the Prompt
<prefix> :
A : appears at the bottom of the screen. Type a tmux command and press Enter. That's it.
Example:
<prefix> :new-window -n logs
Creates a new window named "logs". Every binding in tmux is a shortcut for one of these commands; you can always skip the binding and type the command directly.
Listing Commands
<prefix> :list-commands
Shows every command tmux knows. Long output. Pipe it:
<prefix> :list-commands | grep window
Works because list-commands goes to the currently focused pane's stdout.
Help on a single command:
<prefix> :command-prompt
Or from the shell:
tmux list-commands | grep split-window
tmux list-commands split-window
The Target Syntax
Most commands take a -t flag that specifies what they operate on. The full form:
session:window.pane
All parts are optional:
work session named "work"
work:0 window 0 of work
work:editor window named "editor" of work
work:0.1 pane 1 of window 0 of work
:1 window 1 of the current session
.0 pane 0 of the current window
Examples:
<prefix> :split-window -t work:0
<prefix> :send-keys -t work:shell "make test" Enter
<prefix> :kill-pane -t :1.0
You'll most often omit the target entirely, letting tmux default to the current window and pane:
<prefix> :split-window -h
Targets the current pane. New split appears next to it.
Special targets
{last} the last-used session/window/pane
{next} next window
{prev} previous window
{start} first window in the session
{end} last window
{top} top pane
{bottom} bottom pane
{left} leftmost pane
{right} rightmost pane
{up-of} the pane above (only for pane ops)
{down-of} the pane below
<prefix> :kill-pane -t {last}
<prefix> :select-window -t {next}
Niche, but useful in scripts.
Command Chaining
Run two commands in one prompt submission using ;:
<prefix> :split-window -h ; split-window -v
Creates two splits in sequence. Works for a series of independent commands.
For conditional or shell-ish logic, use the shell:
<prefix> :run-shell "echo hello"
run-shell runs a shell command in the background and optionally displays the output.
Sending Keystrokes: send-keys
The workhorse of tmux scripting.
<prefix> :send-keys "ls" Enter
Sends the literal characters l, s, then the Enter key to the currently focused pane. The pane runs ls.
Target a different pane:
<prefix> :send-keys -t work:shell "make test" Enter
Named keys you can send (a partial list):
Enter the Enter key
Space a space
Tab a tab
Escape escape
BSpace backspace
Up Down Left Right arrows
F1 through F12 function keys
C-c Ctrl+C
M-x Alt+X
Concatenate them as arguments:
<prefix> :send-keys "echo foo" Enter "echo bar" Enter
Running Shell Commands
<prefix> :run-shell "git status"
Output goes to a popup window in modern tmux, or the currently focused pane's standard output in older versions. For output that matters, send it somewhere explicit:
<prefix> :run-shell "git status > /tmp/status"
Non-blocking; the command runs in the background and tmux keeps working. For blocking (wait for completion and show output):
<prefix> :run-shell -b "sleep 5 && tmux display-message done"
Displaying Messages
<prefix> :display-message "hello"
Shows a message in the status bar for a few seconds. Useful in scripts:
<prefix> :display-message "synced at #{T:%H:%M}"
The #{T:...} is a format string for the current time. More on format strings in chapter 8.
The Interactive Prompt
Some commands include an interactive prompt:
<prefix> :command-prompt -p "name:" "rename-window '%%'"
Prompts for a string, substitutes it into the command. %% is the input. The default rename-window binding (<prefix> ,) is wired up like this.
Running Commands From the Shell
Everything in the command prompt works from outside tmux too:
tmux split-window -h -t work:0
tmux send-keys -t work:shell "make test" Enter
tmux new-window -t work -n logs "tail -f /var/log/app.log"
That last one starts a new window and runs a command in it immediately. The argument after the name is the command to run in the new window's shell.
Aliases and Short Forms
Most commands have short aliases:
new-session new, nes
new-window neww
split-window splitw
select-pane selectp
send-keys send
kill-session kill-ses
list-sessions ls
list-windows lsw
list-panes lsp
man tmux lists them all. Once you know the full names, the aliases save keystrokes.
The Command Prompt as a REPL
A quick loop to learn what each command does: open <prefix> :, type a command, watch what happens, undo manually if needed. Every binding you press is syntactic sugar over these commands. Seeing them directly makes the whole system click.
Try:
<prefix> :new-window
<prefix> :rename-window logs
<prefix> :kill-window
<prefix> :last-window
<prefix> :display-message "#{session_name}:#{window_index}"
That last one shows format strings, which are covered in chapter 8.
Common Pitfalls
"I typed a command and nothing happened." tmux probably printed an error. Check the status line briefly, or run <prefix> :show-messages to see recent messages.
"Command prompt pre-fills text and I want it blank." <prefix> : with no pre-fill shows a blank prompt. If you bound a key that pre-fills (<prefix> :new-window leaves new-window in the prompt), press C-u to clear.
"I wanted to pass a space in a send-keys argument." Quote it:
<prefix> :send-keys "hello world" Enter
Or escape:
<prefix> :send-keys hello\ world Enter
"send-keys to another pane doesn't work." Check the target:
<prefix> :list-panes -a
Shows every pane with its full target. Use a full target in send-keys -t.
"I want to run a tmux command and then a shell command, sequentially." run-shell is asynchronous. Use ; to chain tmux commands, but shell chaining belongs inside the shell string: run-shell "a && b".
Next Steps
Continue to 07-configuration.md to start shaping tmux to your hands.