Skip to content

5.6b 快捷键

💡 一句话总结:配置个性化快捷键,提高操作效率。


学完你能做什么

  • 理解快捷键配置结构
  • 能创建自定义快捷键
  • 能导入/导出配置
  • 能使用快捷键管理

🎒 开始前的准备

确保你已经完成以下事项:

  • [ ] 完成必修课程
  • [ ] 了解基本配置

核心思路

快捷键格式

组合键: 操作

配置结构

基础快捷键

yaml
keybindings:
  # 文件操作
  "ctrl+n": "newFile"
  "ctrl+s": "saveFile"
  "ctrl+w": "closeFile"
  "ctrl+shift+s": "saveAs"
  
  # 编辑操作
  "ctrl+c": "copy"
  "ctrl+v": "paste"
  "ctrl+x": "cut"
  "ctrl+z": "undo"
  "ctrl+shift+z": "redo"
  "ctrl+a": "selectAll"
  
  # 导航操作
  "ctrl+p": "quickOpen"
  "ctrl+shift+p": "commandPalette"
  "ctrl+g": "goToLine"
  "ctrl+f": "find"
  "ctrl+h": "replace"

高级配置

yaml
keybindings:
  # 带条件的快捷键
  - key: "ctrl+enter"
    command: "runCode"
    when: "editorHasFocus"
  
  - key: "ctrl+b"
    command: "toggleSidebar"
    when: "always"
  
  # 多步快捷键
  - key: "ctrl+k ctrl+c"
    command: "addComment"
  
  # 特定模式
  - key: "tab"
    command: "emmetExpand"
    when: "editor.emmet.active"
  
  # 鼠标配合
  - key: "ctrl+click"
    command: "goToDefinition"
    when: "editorHasFocus"

预设配置

VS Code 风格

yaml
keybindings:
  preset: "vscode"
  
  custom:
    "ctrl+`": "toggleTerminal"
    "ctrl+shift+n": "newWindow"
    "alt+left": "goBack"
    "alt+right": "goForward"

Emacs 风格

yaml
keybindings:
  preset: "emacs"
  
  custom:
    "ctrl+x ctrl+f": "openFile"
    "ctrl+x ctrl-s": "saveFile"
    "ctrl+x ctrl-w": "saveAs"
    "ctrl+x ctrl+c": "exit"

跟我做

实战:创建个人快捷键配置

yaml
keybindings:
  # 基础操作
  "ctrl+n": "newFile"
  "ctrl+s": "saveFile"
  "ctrl+w": "closeTab"
  "ctrl+shift+t": "reopenTab"
  
  # 开发操作
  "ctrl+enter": "runCode"
  "ctrl+shift+enter": "runTests"
  "f5": "debugStart"
  "f8": "debugContinue"
  
  # AI 交互
  "ctrl+alt+i": "aiChat"
  "ctrl+alt+r": "aiRefactor"
  "ctrl+alt+g": "aiGenerate"
  
  # 搜索
  "ctrl+p": "quickFile"
  "ctrl+shift+p": "commands"
  "ctrl+shift+f": "searchAll"
  "ctrl+shift+h": "searchReplace"
  
  # 导航
  "f12": "goToDefinition"
  "ctrl+-": "goBack"
  "ctrl+shift+-": "goForward"
  
  # 多步快捷键
  "ctrl+k ctrl+b": "toggleSidebar"
  "ctrl+k ctrl+f": "formatSelection"
  "ctrl+k ctrl+c": "addComment"
  
  # 终端
  "ctrl+`": "toggleTerminal"
  "ctrl+shift+`": "newTerminal"

管理命令

bash
# 导出快捷键
opencode keybindings export > keybindings.json

# 导入快捷键
opencode keybindings import keybindings.json

# 重置为默认
opencode keybindings reset

# 查看当前配置
opencode keybindings list

检查点 ✅

全部通过才能继续

  • [ ] 理解快捷键配置
  • [ ] 能创建快捷键
  • [ ] 能使用多步快捷键
  • [ ] 能导入导出配置

本课小结

你学会了:

  1. 快捷键配置结构
  2. 创建自定义快捷键
  3. 条件快捷键
  4. 多步快捷键
  5. 导入导出管理

下一课预告

下一课我们将学习 MCP 扩展,连接外部服务。


📚 更多完整模板Prompt 模板库