Skip to content

Keyboard Shortcuts Reference

Default Keyboard Shortcuts

General Shortcuts

ShortcutAction
Ctrl+X HShow help dialog
Ctrl+X NStart a new session
Ctrl+X UUndo last message
Ctrl+X RRedo undone message
Ctrl+X CCompact/summarize current session
Ctrl+X MList available models
Ctrl+X LList and switch sessions
Ctrl+X SCreate public link to share conversation
Ctrl+X XExport conversation as Markdown
Ctrl+X EOpen external editor for message
Ctrl+X ICreate/update AGENTS.md
Ctrl+X DToggle tool execution details
Ctrl+X QExit OpenCode
ShortcutAction
Up ArrowCycle through command history
Down ArrowCycle through command history
TabAuto-complete commands and file paths
Ctrl+CCancel current input
Ctrl+LClear terminal screen

Editor Shortcuts

ShortcutAction
Ctrl+AMove cursor to start of line
Ctrl+EMove cursor to end of line
Ctrl+KDelete from cursor to end of line
Ctrl+UDelete entire line
Ctrl+WDelete word before cursor
Alt+FMove forward one word
Alt+BMove backward one word

Customizing Keyboard Shortcuts

OpenCode allows you to customize keyboard shortcuts to match your workflow and preferences. Here’s how to configure custom shortcuts:

Configuration File

Shortcuts are configured in the OpenCode configuration file. The location depends on your operating system:

macOS/Linux:

~/.config/opencode/config.toml
# or
$XDG_CONFIG_HOME/opencode/config.toml

Windows:

%APPDATA%\opencode\config.toml

Configuration Format

To customize shortcuts, add a [shortcuts] section to your config file:

[shortcuts]
# General shortcuts
help = "Ctrl+X H"
new_session = "Ctrl+X N"
undo = "Ctrl+X U"
redo = "Ctrl+X R"
compact = "Ctrl+X C"
models = "Ctrl+X M"
sessions = "Ctrl+X L"
share = "Ctrl+X S"
export = "Ctrl+X X"
external_editor = "Ctrl+X E"
init = "Ctrl+X I"
toggle_details = "Ctrl+X D"
exit = "Ctrl+X Q"

Key Syntax

When defining shortcuts, use the following syntax:

  • Ctrl+ for Control key
  • Alt+ for Alt/Option key
  • Shift+ for Shift key
  • Single letters or numbers

Examples:

  • Ctrl+X H (Control + X followed by H)
  • Alt+S (Alt + S)
  • Ctrl+Shift+Q (Control + Shift + Q)

Efficiency Benefits of Keyboard Shortcuts

Keyboard shortcuts significantly improve your workflow efficiency in OpenCode. Here’s how they enhance your productivity:

1. Faster Navigation

  • Quick access to commands: Execute common actions without menu navigation
  • Reduced mouse usage: Minimize context switching between keyboard and mouse
  • Streamlined workflow: Perform tasks in fewer keystrokes

2. Context Switching Reduction

  • Maintain focus: Stay in the flow of your work
  • Less cognitive load: Muscle memory reduces decision-making
  • Continuous workflow: Execute commands without breaking your train of thought

3. Increased Productivity

  • Time savings: Quick actions add up over time
  • Batch processing: Execute multiple commands rapidly
  • Consistency: Standardized shortcuts across sessions

4. Ergonomic Benefits

  • Reduced strain: Less mouse movement and clicking
  • Comfortable positioning: Maintain natural hand placement
  • Sustainable coding: Better posture and reduced fatigue

Advanced Shortcut Techniques

Chord Shortcuts

OpenCode uses chord shortcuts (two-key combinations) for many commands, like Ctrl+X H. This allows for a larger number of unique shortcuts without conflicts.

How to use chord shortcuts:

  1. Press and hold the first key combination (e.g., Ctrl+X)
  2. Release both keys
  3. Press the second key (e.g., H)

Custom Command Shortcuts

You can create custom commands and assign shortcuts to them. See the Slash Commands Reference for details on creating custom commands.

Shortcut Learning Tips

  • Start with the most common shortcuts: Focus on Ctrl+X N (new session), Ctrl+X H (help), and Ctrl+X Q (exit)
  • Use the help dialog: Press Ctrl+X H to see all available shortcuts
  • Practice regularly: Repetition builds muscle memory
  • Create a cheat sheet: Print or save the shortcut table for quick reference
  • Customize for your workflow: Adjust shortcuts to match your most frequent tasks

Troubleshooting Shortcuts

Common Issues

  • Shortcut not working: Check for conflicts with system or terminal shortcuts
  • Inconsistent behavior: Ensure you’re using the correct chord sequence
  • Custom shortcut not recognized: Verify the syntax in your config file
  • Terminal-specific issues: Some terminals may handle certain key combinations differently

Terminal Compatibility

If you’re experiencing issues with shortcuts, check your terminal emulator settings. Some terminals require specific configuration to properly handle certain key combinations.

Resetting to Defaults

To reset all shortcuts to their default values, remove the [shortcuts] section from your config file or comment out the customizations.


Summary

Keyboard shortcuts are a powerful tool for enhancing your OpenCode workflow. By learning and customizing shortcuts, you can:

  • Work faster with reduced keystrokes and mouse usage
  • Maintain focus by minimizing context switching
  • Reduce fatigue through ergonomic key combinations
  • Customize your environment to match your preferences

Take the time to learn the most common shortcuts and gradually incorporate them into your workflow. Over time, they’ll become second nature, allowing you to work more efficiently and effectively with OpenCode.