# Keybindings

This page lists the current CRIEW TUI keys by page and modal state.
Use it for operator reference,
training material,
and future screenshots or annotated UI guides.

## Scope

- Key behavior is state-dependent.
  The same key can mean page toggle,
  completion,
  or indentation depending on the active modal surface.
- `ui.keymap` affects only the main page navigation layer.
  Reply editing,
  config editing,
  search,
  and the inline code editor keep their own fixed bindings.
- The current source of truth is the TUI input handler in
  `src/ui/tui/input.rs`.

## Main pages

### Suggested image slot

- Suggested file:
  `images/keybindings-main-pages.png`
- Suggested capture:
  Mail page and code-browser page with the header keymap label visible.

### Shared page keys

- `:`:
  Open the command palette.
  This is the preferred entry key.
- `F1`:
  Toggle the command palette open or closed.
- `Ctrl+backtick`:
  Toggle the command palette.
  CRIEW also accepts several terminal-specific encodings of the same shortcut.
- `Tab`:
  Toggle between the Mail page and the Code Browser page.
  This fails when no kernel tree is configured.
- `Enter`:
  Act on the current selection.
  On the Mail page it opens the selected mailbox or thread.
  On the Code Browser tree it expands,
  collapses,
  or selects the current row.
- `Esc`:
  Show the reminder to use the command palette.
- `q`:
  Does not exit from the main page.
  CRIEW tells you to use the command palette instead.
- `Ctrl+C`:
  Does not exit from the main page.
  CRIEW tells you to use the command palette instead.

### Main navigation by `ui.keymap`

- `ui.keymap = "default"`:
  `j` and `l` move focus between panes.
  `i` and `k` move inside the focused pane.
  `count+i` and `count+k` repeat vertical movement.
- `ui.keymap = "vim"`:
  `h` and `l` move focus between panes.
  `j` and `k` move inside the focused pane.
  `count+j` and `count+k` repeat vertical movement.
  `gg` jumps to the top of the active pane.
  `G` jumps to the bottom.
  `qq` exits quickly.
- `ui.keymap = "custom"`:
  The active bindings come from `ui.keymap_base`
  plus any overrides from `[ui.custom_keymap]`.
  Open `:keymap` to inspect or change them from the TUI.

The same navigation layer is reused on both top-level pages:

- Mail page:
  focus moves between `Subscriptions`,
  `Threads`,
  and `Preview`.
- Code Browser page:
  focus moves between `Tree` and `Source`.

## Mail page

### Suggested image slot

- Suggested file:
  `images/keybindings-mail-page.png`
- Suggested capture:
  Three-pane mail layout with one subscription selected,
  one thread selected,
  and preview content visible.

### Mail workflow keys

- `/`:
  Open thread search.
  Search is available only on the Mail page.
- `y`:
  Enable the selected subscription.
  Works only when `Subscriptions` has focus.
- `n`:
  Disable the selected subscription.
  Works only when `Subscriptions` has focus.
- `Enter` on `Subscriptions`:
  Open the selected mailbox.
- `Enter` on `Threads`:
  Select the current thread and move focus to `Preview`.
- `-`:
  Select the previous thread while `Preview` keeps focus.
- `=` or `+`:
  Select the next thread while `Preview` keeps focus.
- `e`:
  Open the reply panel when `Preview` has focus.
- `r`:
  Open the reply panel from anywhere on the Mail page.
- `[`:
  Expand the focused mail pane to the left.
- `]`:
  Expand the focused mail pane to the right.
- `{`:
  Shrink the focused mail pane toward the left.
- `}`:
  Shrink the focused mail pane toward the right.
  Pane widths are persisted in `ui-state.toml`.
- `a`:
  Apply the selected patch series.
  Works only when `Threads` has focus.
- `d`:
  Download or export the selected patch series.
  Works only when `Threads` has focus.
- `u`:
  Undo the last patch apply action.
  Works only when `Threads` has focus.

## Code Browser page

### Suggested image slot

- Suggested file:
  `images/keybindings-code-browser.png`
- Suggested capture:
  Tree pane on the left,
  source preview on the right,
  with one real source file selected.

### Code browser keys

- Main page navigation keys still apply here.
  They move between the tree and source panes,
  scroll source preview,
  and support count prefixes or `gg` and `G` when `ui.keymap = "vim"`.
- `Enter` on the tree pane:
  Expand or collapse directories.
  On files,
  keep the file selected and reset source scroll.
- `e` on the source pane:
  Enter the inline code editor.
- `E` on the source pane:
  Open the selected file in external `vim`.

## Command palette

### Suggested image slot

- Suggested file:
  `images/keybindings-command-palette.png`
- Suggested capture:
  Palette open with completion suggestions visible.

### Input keys

- `Esc`:
  Close the palette.
- `Enter`:
  Run the current command.
- `Backspace`:
  Delete one character.
- `Tab`:
  Apply completion.
  A second `Tab` can expand or show the current completion set.
- `F1` or `Ctrl+backtick`:
  Toggle the palette closed again.

### Built-in commands

- `quit` or `exit`:
  Exit CRIEW.
- `restart`:
  Restart the TUI with current startup config.
- `help`:
  Show the built-in command summary.
- `sync`:
  Sync all enabled mailboxes,
  or the current default mailbox when nothing is enabled.
- `sync <mailbox>`:
  Sync one mailbox immediately.
- `config show`:
  Open the visual config editor.
- `keymap`:
  Open the visual keymap editor.
- `config show <key>`:
  Show the file value or effective runtime fallback for one key.
- `config get <key>`:
  Read one config key.
- `config edit [key]`:
  Open the config editor,
  optionally focused on one supported field.
- `config set <key> <value>`:
  Write a TOML value into the config file and reload runtime config.
- `config help`:
  Show config command usage.
- `vim`:
  Open the selected source file in external `vim`.
- `!<shell command>`:
  Run a local shell command.
  CRIEW uses the configured kernel tree as the working directory when one is
  available,
  otherwise it falls back to `HOME`.

## Search

### Suggested image slot

- Suggested file:
  `images/keybindings-search.png`
- Suggested capture:
  Mail page with the search input active and filtered thread results visible.

### Search keys

- `/`:
  Open search on the Mail page.
- `Enter`:
  Apply the current query.
- `Backspace`:
  Delete one character.
- `Esc`:
  Cancel search without applying the current edit.
- Any printable character:
  Append to the current query.

## Config editor

### Suggested image slot

- Suggested file:
  `images/keybindings-config-editor.png`
- Suggested capture:
  Left-side key list,
  right-side field details,
  and one field selected.

### Browse mode

- `Up` or `i`:
  Move to the previous editable field.
- `Down` or `k`:
  Move to the next editable field.
- `Enter` or `e`:
  Start editing the selected field.
- `Tab`:
  Cycle through preset values for the selected field.
- `x`:
  Unset the selected key from the config file.
- `Esc`:
  Close the config editor.

### Edit mode

- Any printable character:
  Append to the current TOML literal.
- `Backspace`:
  Delete one character.
- `Tab`:
  Cycle preset values for the selected field.
- `Enter`:
  Save the current value.
- `Esc`:
  Cancel the edit and return to browse mode.

## Reply panel

### Suggested image slot

- Suggested file:
  `images/keybindings-reply-panel.png`
- Suggested capture:
  Reply panel with editable headers and the body guide line visible.

### Normal mode

- `h`:
  Move the cursor left.
- `l`:
  Move the cursor right.
- `j` or `Down`:
  Move to the next header field or the next body line.
- `k` or `Up`:
  Move to the previous header field or the previous body line.
- `i`:
  Enter insert mode.
- `Enter` or `o`:
  Open a line below and enter insert mode.
- `x`:
  Delete the character under the cursor.
- `p`:
  Open Send Preview.
- `s`:
  Attempt to send.
  CRIEW still requires a confirmed Send Preview before it will actually send.
- `:`:
  Enter reply command mode.
- `Esc`:
  Close the reply panel when the draft is clean.
  If the draft is dirty,
  CRIEW tells you to use `:q!` to discard it.

### Insert mode

- Any printable character:
  Insert at the cursor.
- `Backspace`:
  Delete backward.
- `Enter`:
  Insert a newline.
- `Tab`:
  Insert four spaces.
- `Esc`:
  Return to reply normal mode.

### Command mode

- Any printable character:
  Append to the command line.
- `Backspace`:
  Delete one character.
- `Enter`:
  Run the current command.
- `Esc`:
  Cancel command mode.

Supported reply commands are:

- `:q`
  Close the reply panel only when the draft is clean.
- `:q!`
  Discard the reply draft.
- `:preview`
  Open Send Preview.
- `:send`
  Attempt to send the reply.

## Send Preview and reply notices

### Suggested image slot

- Suggested file:
  `images/keybindings-send-preview.png`
- Suggested capture:
  Send Preview dialog with warning or confirmation text visible.

### Send Preview keys

- `Enter` or `c`:
  Confirm the current preview.
- `s`:
  Attempt to send.
  If preview confirmation is still missing,
  CRIEW opens a blocked-send notice instead.
- `j` or `Down`:
  Scroll preview down.
- `k` or `Up`:
  Scroll preview up.
- `Esc`:
  Close Send Preview and return to the reply editor.

### Reply notice keys

- `Esc` or `Enter`:
  Close the current notice.
- `p`:
  Reopen Send Preview when the notice asks for preview confirmation first.
- `s`:
  Send when the notice says preview confirmation already succeeded.

## Inline code editor

### Suggested image slot

- Suggested file:
  `images/keybindings-inline-code-editor.png`
- Suggested capture:
  Source pane in inline edit mode with cursor and command hint visible.

### Entry conditions

- Start from the Code Browser page.
- Move focus to the `Source` pane.
- Press `e` for inline editing or `E` for external `vim`.

### Normal mode

- `h`:
  Move cursor left.
- `j`:
  Move cursor down.
- `k`:
  Move cursor up.
- `l`:
  Move cursor right.
- `i`:
  Enter insert mode.
- `x`:
  Delete the character under the cursor.
- `s`:
  Save the current buffer.
- `E`:
  Open external `vim`.
- `:`:
  Enter command mode.
- `Esc`:
  Exit edit mode only when the buffer is clean.
  If there are unsaved changes,
  CRIEW tells you to use `:w`,
  `:wq`,
  or `:q!`.

### Insert mode

- Any printable character:
  Insert at the cursor.
- `Backspace`:
  Delete backward or join with the previous line.
- `Enter`:
  Insert a newline.
- `Tab`:
  Insert four spaces.
- `Esc`:
  Return to normal mode.

### Command mode

- Any printable character:
  Append to the command line.
- `Backspace`:
  Delete one character.
- `Enter`:
  Run the current command.
- `Esc`:
  Cancel command mode.

Supported inline editor commands are:

- `:w`
  Save the current file.
- `:q`
  Exit only when the buffer is clean.
- `:q!`
  Discard unsaved changes and exit inline edit mode.
- `:wq`
  Save and exit.
- `:vim`
  Open the same file in external `vim`.

## See also

- [Configuration](Configuration.md)
- [Sync and TUI](Sync-and-TUI.md)
- [Patch and Reply](Patch-and-Reply.md)
