Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

OpenCode Keyboard Shortcuts

OpenCode Keyboard Shortcut Configuration in Detail

OpenCode provides a complete keyboard shortcut system covering various operations such as application control, session management, message browsing, model switching, and input editing.

All shortcuts can be customized through the tui.json file.


Configuration file

Shortcut configurations are written under the tui.json field of the keybinds file; for each entry, the key is the operation name and the value is the corresponding shortcut:

Example

{

  "$schema": "https://opencode.ai/tui.json",

  "keybinds": {

    "leader": "ctrl+x", // leader key setting (see explanation below)

    "session_new": "n", // new session: press the leader key first, then n

    "model_list": "m", // open model list: press the leader key first, then m

    "session_compact": "none" // set the value to "none" to disable this shortcut

  }

}

An operation can be bound to multiple shortcuts, separated by English commas; triggering any one of them executes the operation:

Example

{

  "$schema": "https://opencode.ai/tui.json",

  "keybinds": {

    // The following means: pressing pageup or ctrl+alt+b both page up

    "messages_page_up": "pageup,ctrl+alt+b"

  }

}


Leader Key

Most OpenCode shortcuts use the **Leader Key** mechanism: press the leader key first, then the function key; the two-key combination triggers the corresponding operation. This design avoids conflicts with the terminal's own shortcuts.

The default leader key is ctrl+x. For example, the shortcut for a new session is n, the actual operation is: press ctrl+x, then n。

You can change the leader key to any key combination:

Example

{

  "$schema": "https://opencode.ai/tui.json",

  "keybinds": {

    "leader": "ctrl+x" // change the leader key to other keys, such as "ctrl+space", "alt+x", etc.

                          // the placeholder in the configuration will be automatically replaced with the key set here

  }

}

You don't have to use the leader key mechanism to set shortcuts—you can also bind regular keys or key combinations directly. However, it is recommended to use the leader key first to avoid conflicts with terminal shortcuts.


Disabling Shortcuts

Set the value of any shortcut to "none" to disable the operation; once disabled, pressing any key will not trigger it:

Example

{

  "$schema": "https://opencode.ai/tui.json",

  "keybinds": {

    "session_compact": "none", // disable the "compact session" shortcut

    "scrollbar_toggle": "none", // disable the "toggle scrollbar" shortcut

    "tips_toggle": "none" // disable the "toggle tips" shortcut

  }

}


Complete Shortcut List

1. Application and Interface

Operation Name Default Shortcut Description
app_exit ctrl+c, ctrl+d, q Exit OpenCode
editor_open e Open the current input in an external editor
theme_list t Open the theme list and switch the interface theme
sidebar_toggle b Show or hide the sidebar
scrollbar_toggle None (disabled by default) Show or hide the scrollbar
username_toggle None (disabled by default) Show or hide the username
status_view s View current status information
tool_details None (disabled by default) View tool call details
command_list ctrl+p Open the command palette and search all available commands
tips_toggle h Show or hide usage tips
display_thinking None (disabled by default) Show or hide the model's thinking process
terminal_suspend ctrl+z Suspend the terminal (put OpenCode in the background, return to the shell; type fg to resume)
terminal_title_toggle None (disabled by default) Show or hide the terminal title bar

2. Session Management

Operation Name Default Shortcut Description
session_new n Create a new session
session_list l View the list of all historical sessions
session_export x Export the current session content
session_timeline g View the timeline of the current session
session_fork None (disabled by default) Create a branch session from the current position
session_rename None (disabled by default) Rename the current session
session_share None (disabled by default) Share the current session
session_unshare None (disabled by default) Cancel sharing current session
session_interrupt escape Interrupt the currently running response
session_compact c Compact the current session context to reduce Token usage
session_child_first ↓ Jump to the first child session
session_child_cycle → Cycle forward through child sessions
session_child_cycle_reverse ← Cycle backward through child sessions
session_parent ↑ Return to the parent session

3. Message Browsing

Operation Name Default Shortcut Description
messages_page_up pageup, ctrl+alt+b Page up one page of messages
messages_page_down pagedown, ctrl+alt+f Page down one page of messages
messages_line_up ctrl+alt+y Scroll up one line
messages_line_down ctrl+alt+e Scroll down one line
messages_half_page_up ctrl+alt+u Scroll up half a page
messages_half_page_down ctrl+alt+d Scroll down half a page
messages_first ctrl+g, home Jump to the earliest first message
messages_last ctrl+alt+g, end Jump to the latest last message
messages_next None (disabled by default) Jump to the next message
messages_previous None (disabled by default) Jump to the previous message
messages_last_user None (disabled by default) Jump to the last user message
messages_copy y Copy the current message content to the clipboard
messages_undo u Undo the previous operation
messages_redo r Redo the undone operation
messages_toggle_conceal h Collapse or expand hidden content in a message

4. Models and Agents

Operation Name Default Shortcut Description
model_list m Open the model list and select to switch the currently used model
model_cycle_recent f2 Cycle forward through recently used models
model_cycle_recent_reverse shift+f2 Cycle backward through recently used models
model_cycle_favorite None (disabled by default) Cycle forward through favorite models
model_cycle_favorite_reverse None (disabled by default) Cycle backward through favorite models
variant_cycle ctrl+t Cycle between variants of the current model (such as thinking mode)
agent_list a Open the agent list and select to switch the currently used agent
agent_cycle tab Cycle forward through agents
agent_cycle_reverse shift+tab Cycle backward through agents

5. Input Box Editing

Operation Name Default Shortcut Description
input_submit return Send the current input content
input_newline shift+return, ctrl+return, alt+return, ctrl+j Insert a newline in the input box (without sending)
input_clear ctrl+c Clear the input box content
input_paste ctrl+v Paste clipboard content into the input box
input_move_left left, ctrl+b Move the cursor one character to the left
input_move_right right, ctrl+f Move the cursor one character to the right
input_move_up up Move the cursor one line up
input_move_down down Move the cursor one line down
input_word_forward alt+f, alt+right, ctrl+right Move the cursor forward one word
input_word_backward alt+b, alt+left, ctrl+left Move the cursor backward one word
input_line_home ctrl+a Move to the beginning of the current line
input_line_end ctrl+e Move to the end of the current line
input_visual_line_home alt+a Move to the beginning of the current visual line (a wrapped line)
input_visual_line_end alt+e Move to the end of the current visual line
input_buffer_home home Jump to the very beginning of the entire input box content
input_buffer_end end Jump to the very end of the entire input box content
input_delete_to_line_end ctrl+k Delete all content from the cursor to the end of the current line
input_delete_to_line_start ctrl+u Delete all content from the beginning of the current line to the cursor
input_delete_line ctrl+shift+d Delete the entire line where the cursor is
input_backspace backspace, shift+backspace Delete the character before the cursor
input_delete ctrl+d, delete, shift+delete Delete the character after the cursor
input_delete_word_forward alt+d, alt+delete, ctrl+delete Delete the word after the cursor
input_delete_word_backward ctrl+w, ctrl+backspace, alt+backspace Delete the word before the cursor
input_undo ctrl+-, super+z Undo the previous edit in the input box
input_redo ctrl+., super+shift+z Redo the undone edit

6. Text Selection

Operation Name Default Shortcut Description
input_select_left shift+left Select one character to the left
input_select_right shift+right Select one character to the right
input_select_up shift+up Select one line up
input_select_down shift+down Select one line down
input_select_word_forward alt+shift+f, alt+shift+right Select one word forward
input_select_word_backward alt+shift+b, alt+shift+left Select one word backward
input_select_line_home ctrl+shift+a Select from the cursor position to the beginning of the current line
input_select_line_end ctrl+shift+e Select from the cursor position to the end of the current line
input_select_visual_line_home alt+shift+a Select from the cursor position to the beginning of the current visual line
input_select_visual_line_end alt+shift+e Select from the cursor position to the end of the current visual line
input_select_buffer_home shift+home Select from the cursor position to the very beginning of the input box
input_select_buffer_end shift+end Select from the cursor position to the very end of the input box

7. Input History

Operation Name Default Shortcut Description
history_previous up Recall the previous historical input (valid when the input box is empty)
history_next down Recall the next historical input

Built-in Input Shortcuts in the Desktop Version

The prompt input box of the OpenCode desktop version additionally has a built-in set of Readline / Emacs styleof text editing shortcuts,these shortcuts are built-in features and cannot be tui.json modified or disabled.:

Keyboard shortcut Operation
ctrl+a Move to the beginning of the current line
ctrl+e Move to the end of the current line
ctrl+b Move the cursor backward one character
ctrl+f Move the cursor forward one character
alt+b Move the cursor backward one word
alt+f Move the cursor forward one word
ctrl+d Delete the character at the cursor position
ctrl+k Delete content from the cursor to the end of the line
ctrl+u Delete content from the cursor to the beginning of the line
ctrl+w Delete the previous word
alt+d Delete the next word
ctrl+t Swap the positions of the two characters before and after the cursor
ctrl+g Cancel the current popup window, or abort the running response

Configuring Shift+Enter for Newline

Some terminals by default do not send modified Enter keys (such as Shift+Enter) as separate key presses, causing pressing Shift+Enter in OpenCode to not insert a newline but send the message directly. You need to manually configure the escape sequence for this key in the terminal.

Windows Terminal Configuration

**Step 1:** Open the settings.json file, with the path:

%LOCALAPPDATA%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json

**Step 2:** In the file's root-level actions array, add the following configuration to define an action that sends the Shift+Enter escape sequence:

Example

"actions": [

  {

    "command": {

      "action": "sendInput",

      "input": "\u001b[13;2u" // standard escape sequence for Shift+Enter (CSI u format)

    },

    "id": "User.sendInput.ShiftEnterCustom"

  }

]

**Step 3:** In the file's root-level keybindings array, add a key binding to map Shift+Enter to the action defined above:

Example

"keybindings": [

  {

    "keys": "shift+enter",

    "id": "User.sendInput.ShiftEnterCustom"

  }

]

**Step 4:** After saving the settings.json file, restart Windows Terminal or open a new tab for the configuration to take effect.

If you use another terminal (such as iTerm2, Kitty, Alacritty, etc.), refer to that terminal's documentation, find the 'key mapping' or 'Key bindings' settings, and configure the Shift+Enter to send the \u001b[13;2u escape sequence.