OpenCode 提供了一份可以通过 OpenCode config 进行自定义的 keybinds(快捷键)列表。
```json title=”opencode.json”
{
“$schema”: “https://opencode.ai/config.json“,
“keybinds”: {
“leader”: “ctrl+x”,
“app_exit”: “ctrl+c,ctrl+d,q”,
“editor_open”: “e”,
“theme_list”: “t”,
“sidebar_toggle”: “b”,
“scrollbar_toggle”: “none”,
“username_toggle”: “none”,
“status_view”: “s”,
“tool_details”: “none”,
“session_export”: “x”,
“session_new”: “n”,
“session_list”: “l”,
“session_timeline”: “g”,
“session_fork”: “none”,
“session_rename”: “none”,
“session_share”: “none”,
“session_unshare”: “none”,
“session_interrupt”: “escape”,
“session_compact”: “c”,
“session_child_cycle”: “right”,
“session_child_cycle_reverse”: “left”,
“session_parent”: “up”,
“messages_page_up”: “pageup”,
“messages_page_down”: “pagedown”,
“messages_half_page_up”: “ctrl+alt+u”,
“messages_half_page_down”: “ctrl+alt+d”,
“messages_first”: “ctrl+g,home”,
“messages_last”: “ctrl+alt+g,end”,
“messages_next”: “none”,
“messages_previous”: “none”,
“messages_copy”: “y”,
“messages_undo”: “u”,
“messages_redo”: “r”,
“messages_last_user”: “none”,
“messages_toggle_conceal”: “h”,
“model_list”: “m”,
“model_cycle_recent”: “f2”,
“model_cycle_recent_reverse”: “shift+f2”,
“model_cycle_favorite”: “none”,
“model_cycle_favorite_reverse”: “none”,
“variant_cycle”: “ctrl+t”,
“command_list”: “ctrl+p”,
“agent_list”: “a”,
“agent_cycle”: “tab”,
“agent_cycle_reverse”: “shift+tab”,
“input_clear”: “ctrl+c”,
“input_paste”: “ctrl+v”,
“input_submit”: “return”,
“input_newline”: “shift+return,ctrl+return,alt+return,ctrl+j”,
“input_move_left”: “left,ctrl+b”,
“input_move_right”: “right,ctrl+f”,
“input_move_up”: “up”,
“input_move_down”: “down”,
“input_select_left”: “shift+left”,
“input_select_right”: “shift+right”,
“input_select_up”: “shift+up”,
“input_select_down”: “shift+down”,
“input_line_home”: “ctrl+a”,
“input_line_end”: “ctrl+e”,
“input_select_line_home”: “ctrl+shift+a”,
“input_select_line_end”: “ctrl+shift+e”,
“input_visual_line_home”: “alt+a”,
“input_visual_line_end”: “alt+e”,
“input_select_visual_line_home”: “alt+shift+a”,
“input_select_visual_line_end”: “alt+shift+e”,
“input_buffer_home”: “home”,
“input_buffer_end”: “end”,
“input_select_buffer_home”: “shift+home”,
“input_select_buffer_end”: “shift+end”,
“input_delete_line”: “ctrl+shift+d”,
“input_delete_to_line_end”: “ctrl+k”,
“input_delete_to_line_start”: “ctrl+u”,
“input_backspace”: “backspace,shift+backspace”,
“input_delete”: “ctrl+d,delete,shift+delete”,
“input_undo”: “ctrl+-,super+z”,
“input_redo”: “ctrl+.,super+shift+z”,
“input_word_forward”: “alt+f,alt+right,ctrl+right”,
“input_word_backward”: “alt+b,alt+left,ctrl+left”,
“input_select_word_forward”: “alt+shift+f,alt+shift+right”,
“input_select_word_backward”: “alt+shift+b,alt+shift+left”,
“input_delete_word_forward”: “alt+d,alt+delete,ctrl+delete”,
“input_delete_word_backward”: “ctrl+w,ctrl+backspace,alt+backspace”,
“history_previous”: “up”,
“history_next”: “down”,
“terminal_suspend”: “ctrl+z”,
“terminal_title_toggle”: “none”,
“tips_toggle”: “h”
}
}
---## Leader key(引导键)OpenCode 对大多数 keybinds 使用了一个 `leader` key(引导键),这样可以避免与你的 terminal(终端)快捷键发生冲突。默认情况下,`ctrl+x` 是 leader key,大部分操作都需要先按下 leader key,再按对应的快捷键。例如,要启动一个新的 session(会话),你需要先按 `ctrl+x`,然后再按 `n`。你并不是必须使用 leader key 来定义自己的 keybinds,但官方建议你这样做。---## Disable keybind(禁用快捷键)你可以通过在 config 中为某个 keybind 设置值为 `"none"` 来禁用它。```json title="opencode.json"{ "$schema": "https://opencode.ai/config.json", "keybinds": { "session_compact": "none" }}
Desktop prompt shortcuts(桌面输入框快捷键)
OpenCode desktop app 的 prompt input(输入框)支持常见的 Readline / Emacs 风格的文本编辑快捷键。
这些快捷键是内置的,目前无法通过 opencode.json 进行配置。
| Shortcut |
Action |
ctrl+a |
移动到当前行的起始位置 |
ctrl+e |
移动到当前行的末尾 |
ctrl+b |
光标向后移动一个字符 |
ctrl+f |
光标向前移动一个字符 |
alt+b |
光标向后移动一个单词 |
alt+f |
光标向前移动一个单词 |
ctrl+d |
删除光标所在位置的字符 |
ctrl+k |
删除从光标到行尾的内容 |
ctrl+u |
删除从光标到行首的内容 |
ctrl+w |
删除前一个单词 |
alt+d |
删除后一个单词 |
ctrl+t |
交换相邻字符位置 |
ctrl+g |
取消弹出层 / 中断正在运行的响应 |
Shift+Enter
某些 terminal 默认不会把修饰键(modifier keys)与 Enter 一起发送。
你可能需要配置 terminal,将 Shift+Enter 发送为一个 escape sequence(转义序列)。
Windows Terminal
打开你的 settings.json 文件路径:
%LOCALAPPDATA%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json
在根级别的 actions 数组中添加以下内容:
"actions": [ { "command": { "action": "sendInput", "input": "\u001b[13;2u" }, "id": "User.sendInput.ShiftEnterCustom" }]
在根级别的 keybindings 数组中添加以下内容:
"keybindings": [ { "keys": "shift+enter", "id": "User.sendInput.ShiftEnterCustom" }]
保存文件并重启 Windows Terminal,或者打开一个新的 tab(标签页)即可生效。