教程 / 原生 Mac IDE / 自定义快捷键
📝 文字 ● 初级 更新于 2026-05-19

在 LingCode 中自定义快捷键

LingCode 内置了合理的默认快捷键,但如果你的肌肉记忆来自 Cursor、VS Code、JetBrains 或 Vim,这些默认设置可能会让你别扭好几周。只需花五分钟编辑 ~/.claude/keybindings.json,就能省去多年的摩擦。

为什么用文件,而不是菜单

0

大多数编辑器把快捷键藏在一个带搜索框的设置界面里,每行都有一个小小的"编辑"按钮。改一个绑定还好,改十个就很痛苦,换了电脑还无法迁移。

LingCode 将快捷键保存在 ~/.claude/keybindings.json 这个纯 JSON 文件里。你可以:

  • 用你喜欢的文本编辑器直接修改。
  • 与上周的版本做差异比较。
  • 放入 dotfiles 仓库,在多台 Mac 之间同步。
  • 给某个和弦键位加个 TODO 注释,以后再回来处理。

格式非常简洁:一个由 {keys, command} 对象组成的数组,仅此而已。看懂一条,其他的都一样。

打开配置文件

1

在终端中执行:

mkdir -p ~/.claude
touch ~/.claude/keybindings.json
open -e ~/.claude/keybindings.json

如果文件是全新的空文件,粘贴以下骨架并保存:

[
]

空数组的含义是"使用所有默认值,不覆盖任何设置"。你添加的每一条记录,要么替换某个默认绑定,要么注册一个全新的快捷键。LingCode 会在文件保存后热重载,无需重启。

单条绑定的结构

2

每条绑定是一个包含两个字段的对象:

{
  "keys": "cmd+k",
  "command": "chat.focus"
}
  • keys — 按键组合。修饰键为 cmdshiftalt(即 Option)、ctrl,用 + 连接。键名全小写(kenterescapetabupdownleftrightf1f12)。
  • command — 要触发的操作。你可以在聊天中问 LingCode:"list all keybinding commands",查看完整命令列表。

这就是全部语法。以下是几个常见重绑定的示例:

[
  { "keys": "cmd+p",         "command": "file.quickOpen"    },
  { "keys": "cmd+shift+p",   "command": "command.palette"   },
  { "keys": "cmd+b",         "command": "sidebar.toggle"    },
  { "keys": "cmd+j",         "command": "terminal.toggle"   },
  { "keys": "cmd+enter",     "command": "chat.submit"       },
  { "keys": "cmd+l",         "command": "chat.focus"        }
]

重新绑定发送键

3

最常被问到的重绑定:聊天消息如何发送。默认是 Return 发送,Shift+Return 换行。如果你来自一个以多行输入为主的编辑器,可能更习惯反过来——Return 换行,Cmd+Return 发送:

[
  { "keys": "enter",     "command": "chat.newline" },
  { "keys": "cmd+enter", "command": "chat.submit"  }
]

保存文件,聚焦到聊天输入框,绑定立即生效。无需重启 LingCode。

同一个键可以在不同上下文中触发不同命令(例如聊天输入框与编辑器)。LingCode 会根据当前聚焦的视图来决定执行哪个绑定。如果重绑定似乎没有生效,点击你期望触发的视图后再试一次。

和弦绑定——两次按键的快捷方式

4

和弦是两个按键组合的连续输入:先按第一个,再在短时间内按第二个。当单键快捷键已经不够用时非常实用。两个组合之间用空格分隔:

[
  { "keys": "cmd+k cmd+s", "command": "settings.open"        },
  { "keys": "cmd+k cmd+t", "command": "theme.pick"           },
  { "keys": "cmd+k z",     "command": "zenMode.toggle"       },
  { "keys": "cmd+k cmd+r", "command": "keybindings.open"     }
]

VS Code 用户会认出 cmd+k 前缀这个约定——它的存在是因为经过十年的编辑器发展历程,其他助记键已经几乎用完了。

迁移你的编辑器快捷键

5

你不需要手动逐一翻译。直接问 LingCode:

I came from Cursor. Read ~/.claude/keybindings.json and add the
core Cursor shortcuts I'm probably missing — at minimum:
- cmd+k for the inline AI prompt
- cmd+l for chat focus
- cmd+i for inline suggestions
- cmd+. for quick fix
- cmd+; for the model picker

Don't remove any existing bindings. Show me the diff before
saving.

同样的提示词适用于"I came from VS Code"、"I came from JetBrains"、"I came from Vim"。LingCode 熟知各编辑器的标准快捷键集,会追加而非覆盖——但前提是你要求它先展示差异,这样可以避免意外的冲突覆盖。

同一个键在相同上下文中无法触发两个不相关的命令。如果你为内联 AI 添加了 cmd+k,而 LingCode 默认的 cmd+k 和弦前缀与之冲突,则最后一条记录优先生效。编辑后务必重新查看文件,确认实际绑定的是什么。

跨机器同步

6

这个文件就是纯 JSON——把它放进你的 dotfiles 仓库:

cd ~/dotfiles
ln -s ~/.claude/keybindings.json claude-keybindings.json
git add claude-keybindings.json
git commit -m "Add LingCode keybindings"

在新 Mac 上,反向建立符号链接:

mkdir -p ~/.claude
ln -sf ~/dotfiles/claude-keybindings.json ~/.claude/keybindings.json

你的快捷键配置可以随着 shell 配置、编辑器设置和别名一起迁移。把它们当作一套整体来维护。

当某个绑定突然失效

7

按发生频率排列,三种最可能的原因:

  • JSON 格式错误。一个多余的逗号会让整个文件失效。用 python3 -m json.tool ~/.claude/keybindings.json 检查。
  • 焦点上下文不对。该绑定只在某些视图中生效。点击你期望触发的视图后再试。
  • macOS 或其他应用先抢占了该按键。系统快捷键(cmd+spacecmd+tab)和全局工具(Raycast、Alfred、Rectangle)的优先级更高。检查系统设置 → 键盘 → 键盘快捷键。

在排除以上三点之前,不要急于怀疑是绑定本身的问题。

在 LingCode 中使用此功能

8

整个工作流——定位、编辑、重绑定、和弦、同步——已被打包为一个技能。将其放入你的技能文件夹,然后在 LingCode 中说"rebind a shortcut"或"customize keybindings"即可调用:

---
name: keybindings-help
description: Use when the user wants to customize keyboard shortcuts, rebind keys, add chord bindings, or modify ~/.claude/keybindings.json. Triggers: 'rebind ctrl+s', 'add a chord shortcut', 'change the submit key', 'customize keybindings', 'remap key', 'I'm used to Cursor / VS Code / Vim keys', 'keyboard shortcuts'. Actions: edit ~/.claude/keybindings.json, add {keys, command} entry, import Cursor/VS Code/Vim conventions, sync to dotfiles, debug malformed JSON / focus-context issues / OS-level shortcut grabs.
---

Customize LingCode's keyboard shortcuts by editing
~/.claude/keybindings.json directly.

Format: a JSON array of objects, each with two fields:
- keys: the keystroke. Modifiers cmd, shift, alt, ctrl joined with +.
  Key names lowercase (k, enter, escape, tab, arrows, f1..f12).
  Chords are two combos separated by a space ("cmd+k cmd+s").
- command: the action to fire. Run "list all keybinding commands" in
  chat to discover them.

Workflow:
1. Create ~/.claude/keybindings.json if it doesn't exist; seed with
   an empty array [].
2. Identify the user's source-editor convention (Cursor, VS Code,
   JetBrains, Vim) so the proposed bindings match their muscle
   memory.
3. Append entries — never silently replace existing ones unless
   asked. Show a diff first.
4. Validate with `python3 -m json.tool` before declaring done.
5. The file hot-reloads on save — no restart needed.

If a binding doesn't fire, check: JSON validity, focus context (chat
input vs editor vs terminal), and OS/global app shortcuts (Raycast,
Alfred, System Settings → Keyboard Shortcuts) that may grab the key
first.

保存为 ~/.lingcode/skills/keybindings-help/SKILL.md —— 有关具体路径及技能如何被发现,请参阅安装技能教程。

获取 LingCode →

下一步