这篇讲什么 / What this covers
这是一份 Codex 快捷键速查 + 实战解释。它覆盖终端里的 Codex CLI / TUI、Codex 桌面版常见输入行为、任务控制、历史恢复、模式切换,以及为什么某些按键在 iTerm2、Apple Terminal、VS Code 终端、Warp 或 tmux 里会失效。
This is a practical keyboard reference for Codex: the terminal CLI/TUI, desktop input behavior, task control, history, mode switching, and the terminal settings that decide whether a key actually reaches Codex.
版本提醒 / Version note: Codex 更新很快。进入 Codex 后先按
?或打开快捷键帮助,以你当前版本显示的键位为准;本文按 2026-05-22 的 Codex CLI 0.125.x 与 Codex 桌面版工作流整理。
这篇适合谁看 / Who this is for
- 已经会运行
codex,但还主要靠鼠标、复制粘贴、反复删字的人。 - 经常写长 prompt,想快速移动光标、编辑多行、撤销输入的人。
- 用 Codex 做长任务,希望能中断、恢复、后台查看、切换权限模式的人。
- 需要给团队写“Codex 怎么操作”的内部 onboarding 文档的人。
快捷键总览 / Shortcut map
| 快捷键 / Shortcut | 中文作用 | English meaning |
|---|---|---|
? | 显示当前快捷键帮助 | Show active shortcut help |
Ctrl + C | 取消当前输入;必要时退出 | Cancel input; exit when repeated or at prompt |
Ctrl + D | 空输入时退出 | Exit on empty input |
Esc | 中断当前回复或工具调用 | Interrupt the current response/tool call |
Ctrl + L | 清屏 / 重绘终端 | Clear or redraw the terminal |
Shift + Tab | 切换权限 / 自动化模式 | Cycle approval / automation mode |
Ctrl + A | 跳到行首 | Move to beginning of line |
Ctrl + E | 跳到行尾 | Move to end of line |
Ctrl + B | 左移一个字符 | Move backward one character |
Ctrl + F | 右移一个字符 | Move forward one character |
Option + B / Alt + B | 左移一个词 | Move backward one word |
Option + F / Alt + F | 右移一个词 | Move forward one word |
Ctrl + U | 删除光标前内容 | Delete before cursor |
Ctrl + K | 删除光标后内容 | Delete after cursor |
Ctrl + W | 删除前一个词 | Delete previous word |
Ctrl + Y | 粘回刚删除的内容 | Yank deleted text |
Tab | 补全命令、路径或菜单项 | Complete command/path/menu item |
↑ / ↓ | 浏览历史输入或菜单 | Move through history/menu |
Shift + Enter | 插入换行(取决于终端) | Insert newline, terminal-dependent |
Cmd + V / Ctrl + Shift + V | 粘贴多行 prompt | Paste multiline prompt |
会话控制 / Session control
| 快捷键 / Shortcut | 中文详解 | English detail |
|---|---|---|
? | 第一优先级快捷键。Codex 的键位会随版本、终端、桌面版变化,忘了就按它。 | The first shortcut to remember. It shows what your current Codex build and terminal actually support. |
Ctrl + C | 正在输入时清空或取消;任务运行中会请求停止;在空输入处通常用于退出或二次确认退出。 | Cancels input, asks a running task to stop, and can exit from an empty prompt. |
Ctrl + D | 输入框为空时退出。比连按 Ctrl + C 更干净。 | Exits when the input box is empty. Cleaner than repeated Ctrl + C. |
Esc | 中断当前模型输出或工具调用,适合“方向错了,马上停”。 | Interrupts the current model turn/tool call when the run is going in the wrong direction. |
Ctrl + L | 终端显示错位、长输出把屏幕弄乱时重绘。不会清掉上下文。 | Redraws the terminal when output looks broken. It does not clear Codex context. |
实战区分:Esc 是“停这一轮”,Ctrl + C 更像“取消输入 / 退出会话”。如果 Codex 已经改了文件,按键不会自动回滚文件;要让 Codex回滚,需要明确说“撤销刚才对 X 文件的改动”或用 git diff 审查。
Practical distinction: Esc stops the current turn; Ctrl + C cancels or exits. Neither key automatically reverts files already edited.
权限和自动化模式 / Approval and automation modes
| 快捷键 / Shortcut | 中文作用 | English meaning |
|---|---|---|
Shift + Tab | 在常见模式间循环:只读规划、默认确认、自动执行、更高权限模式。 | Cycle between modes such as planning, ask-before-action, automatic execution, and higher-permission modes. |
常见模式解释:
| 模式 / Mode | 中文解释 | English explanation |
|---|---|---|
| Plan / Read-only | 只读分析,不写文件。适合先让 Codex 看项目、列方案。 | Read-only analysis. Best before letting Codex edit. |
| Default / Ask | 写文件、跑敏感命令前询问。适合陌生仓库。 | Asks before writes or sensitive commands. Good for unfamiliar repos. |
| Auto / Workspace-write | 允许在工作区写文件,仍按配置限制危险命令。 | Allows workspace edits while preserving configured safety boundaries. |
| Full auto / Danger | 高自动化,适合一次性目录、容器、受保护 worktree。 | High automation. Use in disposable folders, containers, or protected worktrees. |
英文速记:Plan first, Ask for unknown repos, Auto for repetitive edits, Danger only inside a sandbox you trust.
中文速记:先规划,陌生仓库默认确认,批量活再自动,危险模式只进隔离环境。
输入编辑 / Input editing
Codex 的输入框通常支持 readline / Emacs 风格快捷键。终端、桌面版和远程环境会有差异,但下面这些最值得记。
| 快捷键 / Shortcut | 中文作用 | English meaning |
|---|---|---|
Ctrl + A | 到行首。长 prompt 改开头时必备。 | Move to start of line. |
Ctrl + E | 到行尾。补验收标准时常用。 | Move to end of line. |
Ctrl + B | 左移一个字符。 | Move left one character. |
Ctrl + F | 右移一个字符。 | Move right one character. |
Option + B / Alt + B | 左移一个词。macOS 要把 Option 配成 Meta。 | Move back one word. On macOS, Option must send Meta/Esc+. |
Option + F / Alt + F | 右移一个词。 | Move forward one word. |
Ctrl + U | 删除光标前全部内容。适合重写 prompt。 | Delete everything before cursor. |
Ctrl + K | 删除光标后全部内容。适合保留前半句、重写约束。 | Delete everything after cursor. |
Ctrl + W | 删除光标前一个词。 | Delete previous word. |
Ctrl + Y | 粘回刚刚 kill 掉的文本。 | Yank back deleted text. |
Ctrl + H / Backspace | 删除前一个字符。 | Delete previous character. |
Ctrl + D | 输入不为空时删除光标处字符;空输入时退出。 | Delete character under cursor; exit if input is empty. |
多行输入 / Multiline input
| 操作 / Action | 中文说明 | English note |
|---|---|---|
Shift + Enter | 常见换行方式,但依赖终端是否把组合键正确传给 Codex。 | Common newline shortcut, but terminal-dependent. |
| 粘贴多行 / Paste multiline | 从编辑器写好 spec 再粘贴,最稳。 | Write the spec in an editor, then paste. |
| here-doc 风格 / here-doc style | 长任务可以先放进文件,让 Codex 读取文件。 | For long specs, put them in a file and ask Codex to read it. |
如果 Shift + Enter 不生效:
- iTerm2:检查 Profiles → Keys,Option / Shift 组合不要被全局快捷键截走。
- Apple Terminal:检查 Keyboard 设置,确认组合键没有映射到菜单。
- VS Code terminal:检查
terminal.integrated.commandsToSkipShell和自定义 keybindings。 - tmux:检查
set -g xterm-keys on,并确认外层终端支持该组合。 - Warp:部分组合键由 Warp 自己处理,改用粘贴多行 spec 更稳。
菜单、补全、历史 / Menus, completion, history
| 快捷键 / Shortcut | 中文作用 | English meaning |
|---|---|---|
Tab | 在 / 命令、文件路径、菜单项之间补全或移动。 | Complete or move through slash commands, paths, and menus. |
↑ | 上一条历史输入,或菜单上移。 | Previous input or move up in a menu. |
↓ | 下一条历史输入,或菜单下移。 | Next input or move down in a menu. |
Enter | 发送输入或确认选中项。 | Submit or confirm selection. |
Esc | 关闭菜单或中断当前动作。 | Close menu or interrupt action. |
建议:不要把 200 行需求直接写在 Codex 输入框里。先在 TASK.md 写清楚目标、限制、验收标准,然后对 Codex 说:Read TASK.md and implement it. 这比依赖历史输入安全。
桌面版常用键 / Codex desktop habits
| 快捷键 / Shortcut | 中文作用 | English meaning |
|---|---|---|
Cmd + V | 粘贴 prompt、截图说明、错误日志。 | Paste prompts, logs, or notes. |
Cmd + A | 选中当前输入框内容。 | Select input text. |
Cmd + Z | 撤销输入框里的文字编辑,不是撤销文件改动。 | Undo text editing in the input box, not file edits. |
Cmd + F | 在浏览器 / 文档视图里搜索;具体取决于焦点。 | Search in the focused browser/document view. |
Cmd + W | 关闭窗口或当前视图,注意不要误关任务。 | Close a window/view depending on focus. |
桌面版最容易踩的坑是“焦点不在输入框”。同一个快捷键,焦点在浏览器、终端、编辑器、聊天输入框时效果不同。按之前看一眼光标在哪里。
推荐背诵的 12 个 / The 12 to memorize
| 中文场景 | Shortcut | English scenario |
|---|---|---|
| 看帮助 | ? | Show help |
| 停止跑偏任务 | Esc | Stop a drifting run |
| 退出 | Ctrl + D | Exit |
| 清屏 | Ctrl + L | Redraw screen |
| 切模式 | Shift + Tab | Switch mode |
| 行首 | Ctrl + A | Start of line |
| 行尾 | Ctrl + E | End of line |
| 删前半段 | Ctrl + U | Delete before cursor |
| 删后半段 | Ctrl + K | Delete after cursor |
| 删一个词 | Ctrl + W | Delete word |
| 补全 | Tab | Complete |
| 历史输入 | ↑ | Previous prompt |
失效排查 / When shortcuts fail
| 现象 / Symptom | 中文原因 | English cause | 修复 / Fix |
|---|---|---|---|
Option + B/F 输入奇怪字符 | Option 没有作为 Meta 发送 | Option is not sending Meta | iTerm2 / Terminal 里启用 Esc+ 或 Meta |
Shift + Enter 直接发送 | 终端没传换行组合 | Terminal does not pass the combo | 改用粘贴多行,或配置终端键位 |
Ctrl + S 卡住 | 终端 flow control 暂停输出 | Terminal flow control paused output | 按 Ctrl + Q 恢复;必要时 stty -ixon |
Tab 不补全 | 焦点在外层 shell 或菜单状态不对 | Focus/menu state mismatch | 点回输入框,按 Esc 关闭菜单后重试 |
Cmd 类快捷键无效 | 你在纯终端,不是桌面输入框 | Pure terminal does not receive Cmd shortcuts | 使用终端对应的 Ctrl / Alt 组合 |
和 Claude Code 的差异 / Difference from Claude Code
Codex 和 Claude Code 都支持一批 readline 风格输入键,但产品层的快捷键不完全相同。不要把 Claude Code 的 /terminal-setup、Esc Esc、Ctrl + T 等习惯直接假设到 Codex;在 Codex 里始终以 ? 和当前版本帮助为准。
Both tools share many terminal editing conventions, but product-level shortcuts differ. Treat ? as the source of truth for Codex.
FAQ
Q:Codex 里 Esc 和 Ctrl + C 有什么区别? A:Esc 是“中断当前回复或工具调用”——停这一轮,会话还在。Ctrl + C 是“取消当前输入”,在空输入框上反复按会退出会话。Esc 适合方向跑偏要停下,Ctrl + C 适合清空想重写或退出。
Q:为什么 Option + B / F 在我的终端输入奇怪字符? A:Option 没有被设置成发送 Meta。在 iTerm2 里 Profiles → Keys 启用 “Esc+” 或 “Meta”;Apple Terminal 在 Settings → Profiles → Keyboard 勾选 “Use Option as Meta key”。修完之后按词移动 / 删词那一批快捷键才生效。
Q:Shift + Enter 不换行,直接发送了怎么办? A:终端没有把 Shift + Enter 当成换行组合发给 Codex。最稳的做法是把长 prompt 写在编辑器里粘贴进来,或者放进 TASK.md 让 Codex 读文件;折腾终端键映射收益低。
Q:Shift + Tab 切的“模式”分别是什么? A:常见四档:Plan / Read-only 只分析不写文件;Default / Ask 写文件前询问;Auto / Workspace-write 允许工作区写但仍守危险命令边界;Full auto / Danger 高自动化,只在一次性目录或容器里用。陌生 repo 默认 Ask,批量活才切 Auto。