Your prefix key
December 04, 2026
At the end, Ctrl+A and then a key does in Rex what it does in tmux, from a config file that you wrote, checked and loaded.
Before you start
From memory
From lesson 2: there are two ways to start a program in a new terminal. Write both. Which one does the same as the commands: field of smug, and why does that matter for gitty?
The config file
Rex needs no config file. If you want one, it is ~/.config/rex/init.lua, and it is Lua (Configuration File). Four facts:
- The file runs from top to bottom each time it loads.
require("keys")loadskeys.luafrom the same directory. You can split the config this way.- Rex does not watch the file. You run
rex config reloadto load it. rex config checkloads the file, changes nothing, and reports what it found.
How to write a key
A key is zero or more modifiers and one key, joined with +: cmd+d, ctrl+shift+n. The modifiers are cmd, ctrl, alt and shift (Keyboard Shortcuts).
Two rules are different from tmux.
You write a key without Shift applied. In tmux you write %. In Rex you write shift+5.
A prefix key is a key sequence. You join the keys with >. ctrl+a>c means Ctrl+A, then C (Key Sequences). Escape cancels a sequence that you started.
One line binds a key to an action:
rex.bind("ctrl+a>c", "client.tab.new")
rex.bind("ctrl+a>shift+5", "pane.split", { direction = "right" })The first value is the key. The second is the name of an action. The third is optional: a table of arguments for the action. In Lua, { direction = "right" } is a table with one field.
A key runs an action at once, or it starts a sequence. It cannot do both. After you bind ctrl+a>c, Ctrl+A alone does not reach the shell any more, and in zsh Ctrl+A moves the cursor to the start of the line. Your tmux.conf has the same problem and the same answer: bind-key C-a send-prefix. In Rex, you bind the doubled key to the action pane.send_key.
Your tmux.conf, line by line
| In tmux.conf | In Rex |
|---|---|
set-option -g prefix C-a | Each binding starts with ctrl+a> |
bind-key C-a send-prefix | ctrl+a>ctrl+a runs pane.send_key with { key = "ctrl+a" } |
bind r source-file ... | ctrl+a>r runs client.config.reload |
mode-keys vi, and v and y in copy mode | Copy mode has v to select and y to copy by default. ctrl+a>[ can open it. |
set -g base-index 1 | No line. Rex counts positions from 1. |
default-terminal, terminal-overrides, extended-keys | No line. These fix what tmux does between a program and the terminal. Test Shift+Enter in Claude Code to be sure. |
| Catppuccin, the status line, the pomodoro timer | No match found in the docs that I read. The app has themes: run "Change Theme" from the command palette. |
| tmux-notify | A tab shows when its program works, waits for you, is done or failed, if the program reports it. |
The action names and the default keys of copy mode are in the Mac Actions reference. The tab states are from the Program Status Protocol page.
Write it
Write keys.lua
Make
~/.config/rex/keys.lua. Type it. The small functionkeyadds the prefix, so each line shows only the second key.-- ~/.config/rex/keys.lua -- The prefix key from ~/.config/tmux/tmux.conf, as Rex key sequences. local prefix = "ctrl+a" -- key("c", ...) binds Ctrl+A, then C. local function key(k, action, args) rex.bind(prefix .. ">" .. k, action, args) end -- tmux: bind-key C-a send-prefix. Ctrl+A twice sends one Ctrl+A to the program. key("ctrl+a", "pane.send_key", { key = "ctrl+a" }) -- tmux: bind r source-file ~/.config/tmux/tmux.conf key("r", "client.config.reload") -- Windows. Rex shows a window as a tab. key("c", "client.tab.new") key("n", "client.tab.next") key("p", "client.tab.previous") key(",", "client.tab.rename") for i = 1, 9 do key(tostring(i), "client.tab.goto", { index = i }) end -- Panes. Write a key without Shift applied: % is shift+5 and " is shift+'. key("shift+5", "pane.split", { direction = "right" }) key("shift+'", "pane.split", { direction = "down" }) key("z", "pane.zoom") key("x", "pane.close") key("left", "pane.focus.left") key("right", "pane.focus.right") key("up", "pane.focus.up") key("down", "pane.focus.down") -- Sessions. key("s", "session.switch") key("shift+4", "session.rename") -- tmux: prefix then $ -- Copy mode. In it, v selects and y copies by default, as in your tmux.conf. key("[", "pane.copy_mode.enter")Three pieces of Lua are new.
localmakes a name that exists only in this file...joins two strings.for i = 1, 9 do ... endcounts from 1 to 9 with both ends included.Load it from init.lua
Put one line in
~/.config/rex/init.lua:require("keys")Check, then reload
rex config check rex config reloadcheckmust report 26 bindings and no error. Thenreloadmakes the server read the file and tells the app.Look at what the server has
rex keymap | grep 'ctrl+a'rex keymapasks the running server for the keys that are loaded. Each line shows the key, the action, the arguments and the file and line that made the binding.Use the keys
Try Ctrl+A C, then Ctrl+A %, then Ctrl+A Z two times, then Ctrl+A X. Then type some text at the prompt and press Ctrl+A two times. The cursor must go to the start of the line.
Predict, then test
Do each test, then put the file back.
Test one. In keys.lua, change "pane.zoom" to "pane.zom". Before you run rex config check, write down your answer: does it report an error? Run it. Then run rex config reload and look at the app and at rex keymap.
Test two. Remove the last ) from one line. Write down your answer: after rex config reload, do your other keys still work? Run rex config check, then rex config reload, then try Ctrl+A C.
From memory
After the two tests: who can know that pane.zom is not an action, and who cannot? What does the server do when the file has a syntax error?
Check yourself
Check yourself
Answer from memory. Do not scroll up first.
You bound ctrl+a>c. What does Ctrl+A alone do now?
How do you write the % key in a binding?
You saved init.lua. When does Rex use the new file?
keys.lua has a wrong action name. What does rex config check report?
From lesson 1: which target does Rex try first?
0 of 5 answered
Primary source
One short page. It has a full tmux-style set with ctrl+b, the rule for a key that is bound two ways, and how rex.unbind treats a sequence. The lines of your tmux.conf and their Rex forms are in the tmux and smug map.
Stuck, or curious?
Ask Claude. Paste the output or the error and say what you expected. A follow-up question is part of the lesson, and it tells Claude what to teach next.