# WezTerm 2: Twenty Leader Shortcuts

[![Google Play QR + Dotori Bluetooth Keyboard - Your phone as a keyboard for PC and TV](https://droidactor.github.io/assets/banner/en/bt-keyboard-qr.png align="center")](https://play.google.com/store/apps/details?id=com.droidactor.bt_keyboard&hl=en)

*A free app I built myself. Give it a try.*

In part 1 I made `Ctrl+U` the prefix key and put splits, movement and tabs behind it. Use it for a while and the next problem arrives. Past twenty keys, what your hands remember and what the config file says drift apart. This post puts the key definitions in one table. That table produces both the real bindings and the help screen. It also covers the price of having a prefix key at all.

## Put the key definitions in one table

The examples and attachment were aligned with my PC's configuration on November 5, 2026. The code below shows the core binding and menu structure. The complete file also includes window and session management, ID copying and Herdr integration.

Line up `leader("w", ...)` calls the way part 1 did and there is nowhere to write the description. So bundle key, description and action into one three-column entry. The bindings are generated from that list. The description becomes data rather than a comment.

```lua
local leader_bindings = {
  { "w", "Split left/right (Width)", act.SplitHorizontal({ domain = "CurrentPaneDomain" }) },
  { "v", "Split top/bottom (Vertical)", act.SplitVertical({ domain = "CurrentPaneDomain" }) },
  { "z", "Zoom / restore the current pane", act.TogglePaneZoomState },
  { "h", "Move to the left pane", act.ActivatePaneDirection("Left") },
  { "/", "Command palette", act.ActivateCommandPalette },
}

for _, b in ipairs(leader_bindings) do
  table.insert(keys, { mods = "LEADER", key = b[1], action = b[3] })
end
```

Now put the same list on screen. Bind `act.InputSelector` to `LEADER + .` and the entries appear as an overlay, running the action of whichever one you pick. Add a key and the help grows with it, so the two cannot drift.

These excerpts use `wezterm`, `act`, `config` and `keys` from the existing configuration. The leader is `config.leader = { key = "u", mods = "CTRL", timeout_milliseconds = 2000 }`. Create both callbacks below once when loading the configuration.

```lua
local cheatsheet_choices = {}
for _, b in ipairs(leader_bindings) do
  table.insert(cheatsheet_choices, {
    id = b[1], label = string.format("%-12s%s", b[1], b[2]),
  })
end
table.insert(cheatsheet_choices, {
  id = "", label = "1 - 9, 0    Tabs (1 = first, 0 = tenth; info only)",
})

local cheatsheet_pick = wezterm.action_callback(function(win, p, id)
  if not id or id == "" then return end
  for _, b in ipairs(leader_bindings) do
    if b[1] == id then
      win:perform_action(b[3], p)
      return
    end
  end
end)

local open_cheatsheet = wezterm.action_callback(function(win, pane)
  win:perform_action(act.InputSelector({
    title = "LEADER (Ctrl+U) shortcuts",
    fuzzy = true,
    fuzzy_description = "Search shortcuts (↑↓ move · Enter run · Esc close) : ",
    choices = cheatsheet_choices,
    action = cheatsheet_pick,
  }), pane)
end)

table.insert(keys, { mods = "LEADER", key = ".", action = open_cheatsheet })
-- Apply config.keys = keys after adding all existing bindings.
```

Tab shortcuts are generated in a loop and get one informational menu row. The current configuration numbers tabs from 1: `1` selects the first tab, `9` the ninth, and `0` the tenth. `ActivateTab` takes a zero-based index, so the conversion is:

```lua
for i = 0, 9 do
  table.insert(keys, {
    key = tostring(i), mods = "LEADER",
    action = act.ActivateTab((i + 9) % 10),
  })
end
```

The informational row has an empty `id`, so selecting it runs nothing. Typing numbers inside the menu filters the list. Close it and press `Ctrl+U` followed by a number to switch tabs. The complete file also sets `tab_and_split_indices_are_zero_based = false` and uses `tab_index + 1` in its custom titles to display tabs from 1.

## Two ways the help screen caused misfires

Do not leave out `fuzzy = true`. The default mode of `InputSelector` attaches a quick-select character to each row. That character comes in order from the default `alphabet` field, `1234567890abc…`. It has nothing to do with the shortcut printed on the screen.

In an older version, the fourth entry was "close pane". Pressing `4` to reach tab 4 selected that row instead. Starting in search mode prevents confusion between menu row numbers and tab numbers.

The second issue is when `action_callback` is called. Calling it inside a key handler registers another event handler each time the menu opens. Build the shortcut list and callbacks once at configuration load time. Creating an ordinary table such as `choices` does not itself register a handler.

The complete file reads the current GUI's `pid`, `window`, `tab` and `pane` IDs when opening the menu and adds an `(id)` row. Select it and press Enter to copy those identifiers. They differ from the tab bar's displayed numbers. Only the table containing those changing values is built on each opening; the selection callback is reused.

## Current keys and Herdr integration

Press each key below after `Ctrl+U`. Arrow keys also require the leader first.

| Key | Action |
| --- | --- |
| `c` / `u` | New tab / new window |
| `b` / `n` | Previous tab / next tab |
| `1` to `9`, `0` | First through ninth tab, tenth tab |
| `w` / `v` | Split left/right / top/bottom |
| `h` / `j` / `k` / `l` | Move left / down / up / right between panes |
| Arrow keys | Resize the WezTerm pane by 5 cells; inside Herdr, use Herdr's resize increment |
| `z` | Zoom / restore the current pane |
| `x` | Close the current pane (WezTerm asks for confirmation) |
| `y` | Copy the current WezTerm pane's text, including scrollback |
| `d` / `a` | Move a pane to a new window / bring another tab or window's pane alongside this one |
| `s` / `e` | Attach to / detach from WezTerm's `mux` session |
| `q` | Detach the Herdr screen, leaving work on its server; no action in an ordinary pane |
| `/` / `.` | Command palette / shortcut menu |
| `Ctrl+U` | Send `Ctrl+U` to the inner program |

In the complete file, `herdr = true` marks `w`, `v`, `z`, `x`, `q`, `h/j/k/l` and the arrow keys. When local Herdr is detected, they send its `Ctrl+B` prefix followed by the same key. Both direct shortcuts and menu selections use this routing. Tab, window and WezTerm session keys stay with WezTerm.

This assumes my matching Herdr configuration. Install Herdr separately and set its prefix to `Ctrl+B`, `w` to split left/right, `v` to split top/bottom, and arrows to resize. Detection uses local processes and does not work through SSH, inside WSL or in a WezTerm `mux` domain. Use Herdr's own prefix there. The `a` action also excludes `mux` and `SSHMUX` panes.

When Herdr is detected, the `(id)` row also includes its session, workspace, tab and pane IDs. ID lookup is skipped for `--remote`. Sessions selected only through environment variables cannot be identified and are queried as `default`. Herdr reports focus from the client that last interacted with that session, so another connected client can make these IDs differ from the current screen.

## For what you will not memorise, there is the command palette

You have to decide what gets a shortcut and what does not. Attach every action you use a few times a day to the leader and the list passes twenty again. I handed the rest to the command palette and kept a single `LEADER + /`.

The palette is a modal overlay that searches every command WezTerm knows. Typing narrows it with a fuzzy match, and frequently used commands float to the top. Its default key is `Ctrl+Shift+P`. Pane zoom also has the default `Ctrl+Shift+Z`; my current configuration adds `LEADER + z` to use the same key with Herdr.

## Add a way to send the leader combination to the shell

A single `Ctrl+U` activates the leader and does not reach the shell, so it cannot directly clear text before the cursor in bash. The current configuration sends it through when you press `Ctrl+U` again within the two-second timeout. Keep Ctrl pressed for that second U: pressing an unmodified `u` after the leader opens a new window instead.

```lua
table.insert(keys, {
  mods = "LEADER|CTRL", key = "u",
  action = act.SendKey({ key = "u", mods = "CTRL" }),
})
```

While the leader is armed, even keys that are not bound get swallowed. The official documentation puts it the same way: they are not passed through to the terminal. That is why the ripple indicator in part 1 is not decoration. Without it, the key you press to check whether you are in the waiting state simply disappears. After two seconds the wait clears on its own.

## Summary

Put key, description and action in one table and the bindings and help read the same source. Set `InputSelector` to `fuzzy = true` and create the shortcut list and callbacks once at load time. Read changing information such as current IDs when opening the menu.

Is your key list from part 1 already past ten lines? Move those lines into a three-column table and bind `LEADER + .`.

## Attachment

[Download .wezterm.lua](https://droidactor.github.io/assets/downloads/wezterm.lua)

This is a copy of the complete configuration used on my PC on November 5, 2026. Save it as [`.wezterm.lua`](https://droidactor.github.io/assets/downloads/wezterm.lua) in your home folder. Back up your existing configuration and adjust the Windows Git Bash and MSYS paths, fonts and shell list for your PC. Herdr integration also requires the matching key settings described above. Press `Ctrl+U` then `.` to see all shortcuts. Remember that `s` / `e` control the WezTerm session, while `q` detaches Herdr.

## Related articles

- [WezTerm: One Terminal, CJK and tmux](https://droidactor.hashnode.dev/wezterm-one-terminal-cjk-and-tmux)
- [Herdr: Keep Your Coding AIs in One Place](https://droidactor.hashnode.dev/herdr-keep-your-coding-ais-in-one-place)
- [WezTerm 3: Sessions That Outlive Windows](https://droidactor.hashnode.dev/wezterm-3-sessions-that-outlive-windows)

