Keyboard Shortcuts Reference
Default Keyboard Shortcuts
General Shortcuts
| Shortcut | Action |
|---|---|
Ctrl+X H | Show help dialog |
Ctrl+X N | Start a new session |
Ctrl+X U | Undo last message |
Ctrl+X R | Redo undone message |
Ctrl+X C | Compact/summarize current session |
Ctrl+X M | List available models |
Ctrl+X L | List and switch sessions |
Ctrl+X S | Create public link to share conversation |
Ctrl+X X | Export conversation as Markdown |
Ctrl+X E | Open external editor for message |
Ctrl+X I | Create/update AGENTS.md |
Ctrl+X D | Toggle tool execution details |
Ctrl+X Q | Exit OpenCode |
Navigation Shortcuts
| Shortcut | Action |
|---|---|
Up Arrow | Cycle through command history |
Down Arrow | Cycle through command history |
Tab | Auto-complete commands and file paths |
Ctrl+C | Cancel current input |
Ctrl+L | Clear terminal screen |
Editor Shortcuts
| Shortcut | Action |
|---|---|
Ctrl+A | Move cursor to start of line |
Ctrl+E | Move cursor to end of line |
Ctrl+K | Delete from cursor to end of line |
Ctrl+U | Delete entire line |
Ctrl+W | Delete word before cursor |
Alt+F | Move forward one word |
Alt+B | Move 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 keyAlt+for Alt/Option keyShift+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:
- Press and hold the first key combination (e.g.,
Ctrl+X) - Release both keys
- 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), andCtrl+X Q(exit) - Use the help dialog: Press
Ctrl+X Hto 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.