S11: Vim Mode Vim 模式实现
"Vim is a language" -- 模式编辑是高效输入的艺术。
Harness 层: Vim -- 专业用户的效率工具。
🎯 问题
专业用户习惯 Vim:
- 模式切换编辑
- 快捷键操作
- 高效移动
- 宏和重复
💡 解决方案
Claude Code 实现了完整的 Vim 状态机:
NORMAL ──i──► INSERT
│ │
└────Esc───┘
🔑 状态定义
type VimState =
| { mode: 'INSERT'; insertedText: string }
| { mode: 'NORMAL'; command: CommandState }
type CommandState =
| { type: 'idle' } // 空闲
| { type: 'count'; digits: string } // 计数 (3d)
| { type: 'operator'; op: Operator } // 操作符等待
| { type: 'find'; find: FindType } // 查找
🔧 操作符与移动
d | delete - 删除操作 |
c | change - 修改操作 |
y | yank - 复制操作 |
hjkl | 左/下/上/右移动 |
w/b | 单词前进/后退 |
0/$ | 行首/行尾 |
📝 文本对象
iw / aw
内部/周围单词
i" / a"
引号内/含引号
ib / ab
括号内/含括号