diff --git a/.zed/settings.json b/.zed/settings.json new file mode 100644 index 0000000..1f38d6a --- /dev/null +++ b/.zed/settings.json @@ -0,0 +1,20 @@ +{ + // Vim 模式 — 本项目的核心配置 + "vim_mode": true, + // 相对行号,方便 Vim 的相对跳转(如 5j) + "relative_line_numbers": true, + // 在 Vim 模式下使用系统剪贴板 + "use_system_clipboard": true, + // 光标样式 + "cursor_shape": "bar", + // 显示光标所在位置的列指示 + "cursor_blink": false, + // 缩进参考线 + "indent_guides": { + "enabled": true + }, + // 自动格式化 + "format_on_save": "on", + // 代码折叠 + "fold_depth": 3 +} diff --git a/01-basics/README.md b/01-basics/README.md index b351658..5c6db1d 100644 --- a/01-basics/README.md +++ b/01-basics/README.md @@ -5,12 +5,14 @@ ## 任务清单 ### 任务 1:启用 Vim 模式 + - [ ] 在 Zed 中按 `Ctrl+Shift+P` 打开命令面板 - [ ] 输入 `toggle vim mode` 并回车 - [ ] 确认左下角状态栏显示 `NORMAL`(普通模式) - [ ] 打开 `01-basics/practice.ts` 开始练习 ### 任务 2:掌握四种核心模式 + - [ ] **Normal(普通模式)**:按 `Esc` 进入(光标是方块),用于导航和命令 - [ ] **Insert(插入模式)**:按 `i` 进入(光标是竖线),用于输入文字 - [ ] **Visual(可视模式)**:按 `v` 进入,用于选择文本 @@ -18,6 +20,7 @@ - [ ] 反复练习:`i` → 打字 → `Esc` → 移动 → `v` → 选择 → `Esc` ### 任务 3:基本移动(hjkl) + - [ ] 在 Normal 模式下使用 `h` `j` `k` `l` 代替方向键 - [ ] 打开 `practice.ts`,按 `j` 向下移动到第 30 行 - [ ] 按 `k` 向上移动回第 1 行 @@ -25,6 +28,7 @@ - [ ] **禁止使用鼠标和方向键 5 分钟** ### 任务 4:文件操作 + - [ ] `:w` — 保存文件 - [ ] `:q` — 关闭文件 - [ ] `:wq` — 保存并关闭 @@ -34,7 +38,9 @@ - [ ] `Ctrl+w h/j/k/l` — 在窗格间移动 ### 任务 5:练习文件操作 + 打开 `practice.ts`,完成以下操作: + - [ ] 在文件末尾用 `o`(小写)在下方新增一行并进入插入模式 - [ ] 在文件开头用 `O`(大写)在上方新增一行并进入插入模式 - [ ] 用 `a` 在光标后追加,用 `A` 在行尾追加 @@ -46,6 +52,7 @@ ## 自查标准 在进入下一阶段前,确保你能盲操作(不看键盘): + - [ ] 50 次 hjkl 移动不出错 - [ ] 10 次 i → 打字 → Esc 不出错 - [ ] 3 次 :w → :q → 重新打开文件不出错 diff --git a/06-integration/project/calculator.ts b/06-integration/project/calculator.ts index 95d5346..952133b 100644 --- a/06-integration/project/calculator.ts +++ b/06-integration/project/calculator.ts @@ -12,11 +12,7 @@ export class Calculator { } multiply(a: number, b: number): number { - let result = 0; - for (let i = 0; i < Math.abs(b); i++) { - result += a; - } - return b < 0 ? -result : result; + return a * b; } divide(a: number, b: number): number { diff --git a/06-integration/project/index.ts b/06-integration/project/index.ts index f4db206..d610907 100644 --- a/06-integration/project/index.ts +++ b/06-integration/project/index.ts @@ -6,7 +6,7 @@ import { Calculator } from "./calculator"; import { Formatter, type FormatOptions } from "./formatter"; import { DataStore } from "./store"; -import { logger, LogLevel } from "./utils/logger"; +import { logger, LogLevel } from "./logger"; // TODO: Add more test cases // FIXME: Handle edge cases for negative numbers diff --git a/CHEATSHEET.md b/CHEATSHEET.md index d95dfb7..2f20ec8 100644 --- a/CHEATSHEET.md +++ b/CHEATSHEET.md @@ -15,6 +15,25 @@ --- +## 必杀技(高频) + +| 按键 | 行为 | +|------|------| +| `.` | 重复上次修改(Vim 最强按键) | +| `u` / `Ctrl+r` | 撤销 / 重做 | +| `gi` | 回到上次插入位置 | +| `g;` / `g,` | 跳转到上/下一个修改位置 | +| `Ctrl+o` / `Ctrl+i` | 跳回/前进(跳转列表) | +| `xp` | 交换光标后两个字符 | +| `J` | 合并当前行和下一行 | +| `~` | 切换光标字符大小写 | +| `Ctrl+a` / `Ctrl+x` | 数字 +1 / -1 | +| `gg=G` | 格式化整个文件 | +| `:%s/old/new/g` | 全文替换 | +| `:g/pat/d` | 删除所有匹配 `pat` 的行 | + +--- + ## 移动(Motion) ### 基础 diff --git a/challenges/code-golf-1-func-sig.ts b/challenges/code-golf-1-func-sig.ts new file mode 100644 index 0000000..8790e14 --- /dev/null +++ b/challenges/code-golf-1-func-sig.ts @@ -0,0 +1,25 @@ +// ============================================================ +// Code Golf 场景 1:函数签名修改 +// ============================================================ +// +// 目标:用最少的 Vim 按键把下面的代码改成目标代码。 +// 记录你的按键数! +// +// 💡 提示:c w 改单词、f ( 跳到括号、c i ( 修改参数、A 行尾追加 +// ============================================================ + +function greet(name: string): string { + return "Hello, " + name; +} + +// === 目标代码(用最少按键达到) === +// +// function sayHelloTo(firstName: string, lastName: string): string { +// return `Hello, ${firstName} ${lastName}!`; +// } +// +// ============================================================ +// 我的最佳成绩: +// 日期: ________ 按键数: ________ +// 操作日志: ________________________________ +// ============================================================ diff --git a/challenges/code-golf-2-reorder.ts b/challenges/code-golf-2-reorder.ts new file mode 100644 index 0000000..379798d --- /dev/null +++ b/challenges/code-golf-2-reorder.ts @@ -0,0 +1,30 @@ +// ============================================================ +// Code Golf 场景 2:对象属性重排 +// ============================================================ +// +// 目标:把 id 属性移到最后,用最少按键。 +// +// 💡 提示:d d 删除行、p 粘贴、V 行选择、:m 移动 +// ============================================================ + +const user = { + id: 1, + name: "Alice", + email: "alice@example.com", + age: 30, +}; + +// === 目标代码 === +// +// const user = { +// name: "Alice", +// email: "alice@example.com", +// age: 30, +// id: 1, +// }; +// +// ============================================================ +// 我的最佳成绩: +// 日期: ________ 按键数: ________ +// 操作日志: ________________________________ +// ============================================================ diff --git a/challenges/code-golf-3-batch-comment.ts b/challenges/code-golf-3-batch-comment.ts new file mode 100644 index 0000000..a3639ad --- /dev/null +++ b/challenges/code-golf-3-batch-comment.ts @@ -0,0 +1,43 @@ +// ============================================================ +// Code Golf 场景 3:批量加注释 +// ============================================================ +// +// 目标:给三个函数上面各加一行注释 "// Arithmetic operation: <函数名>" +// +// 💡 提示:用宏!q a 开始录制 → 在第一行编辑 → j → q 停止 → @a 回放 +// ============================================================ + +function add(a: number, b: number): number { + return a + b; +} + +function subtract(a: number, b: number): number { + return a - b; +} + +function multiply(a: number, b: number): number { + return a * b; +} + +// === 目标代码 === +// +// // Arithmetic operation: add +// function add(a: number, b: number): number { +// return a + b; +// } +// +// // Arithmetic operation: subtract +// function subtract(a: number, b: number): number { +// return a - b; +// } +// +// // Arithmetic operation: multiply +// function multiply(a: number, b: number): number { +// return a * b; +// } +// +// ============================================================ +// 我的最佳成绩: +// 日期: ________ 按键数: ________ +// 操作日志: ________________________________ +// ============================================================ diff --git a/challenges/code-golf-4-array-to-obj.ts b/challenges/code-golf-4-array-to-obj.ts new file mode 100644 index 0000000..0fd118b --- /dev/null +++ b/challenges/code-golf-4-array-to-obj.ts @@ -0,0 +1,28 @@ +// ============================================================ +// Code Golf 场景 4:数组转对象 +// ============================================================ +// +// 目标:在 keys/values 上方创建 person 对象,用最少按键。 +// +// 💡 提示:O 在上方插入、手动拼对象、或 y i w + p 配合编辑 +// ============================================================ + +const keys = ["name", "age", "email"]; +const values = ["Alice", 30, "alice@example.com"]; + +// === 目标代码 === +// +// const person = { +// name: "Alice", +// age: 30, +// email: "alice@example.com", +// }; +// +// const keys = ["name", "age", "email"]; +// const values = ["Alice", 30, "alice@example.com"]; +// +// ============================================================ +// 我的最佳成绩: +// 日期: ________ 按键数: ________ +// 操作日志: ________________________________ +// ============================================================ diff --git a/challenges/code-golf-5-delete-logs.ts b/challenges/code-golf-5-delete-logs.ts new file mode 100644 index 0000000..9418331 --- /dev/null +++ b/challenges/code-golf-5-delete-logs.ts @@ -0,0 +1,41 @@ +// ============================================================ +// Code Golf 场景 5:删除所有 console.log +// ============================================================ +// +// 目标:删除函数体内所有 console.log 语句,用最少按键。 +// +// 💡 提示:g l 选中所有 console.log → d 删除它们! +// 或者::g/console\.log/d 全局删除匹配行 +// ============================================================ + +function process(): void { + console.log("Starting..."); + const a = doThing(); + console.log("After thing:", a); + const b = doOtherThing(); + console.log("After other:", b); + console.log("Done!"); + return b; +} + +function doThing(): number { + return 42; +} + +function doOtherThing(): number { + return 84; +} + +// === 目标代码 === +// +// function process(): void { +// const a = doThing(); +// const b = doOtherThing(); +// return b; +// } +// +// ============================================================ +// 我的最佳成绩: +// 日期: ________ 按键数: ________ +// 操作日志: ________________________________ +// ============================================================ diff --git a/challenges/code-golf.md b/challenges/code-golf.md index 70189ed..2d0fad5 100644 --- a/challenges/code-golf.md +++ b/challenges/code-golf.md @@ -6,6 +6,7 @@ - 只能用 Vim 快捷键,不能使用鼠标 - 记录按键数(不包括撤销的 `u`) - 每次完成后在表格填入你的最佳成绩 +- 📁 每个场景都有对应的 `.ts` 练习文件在 `challenges/` 目录下,直接打开即可练习 --- diff --git a/challenges/daily-practice.md b/challenges/daily-practice.md index 063a0d8..0ef020f 100644 --- a/challenges/daily-practice.md +++ b/challenges/daily-practice.md @@ -56,3 +56,38 @@ | 5 | / 搜索 + n | 12 | 多光标 gl | 19 | Speed Drill | | 6 | 文本对象 i/a | 13 | Surround ys/ds/cs | 20 | 综合挑战 | | 7 | 操作符 d/c/y | 14 | 可视模式 V/v | 21 | 终极大挑战 | + +--- + +## 🗓 周末回顾模板 + +> 每周六/日花 15 分钟回顾,比每天练习更重要。 + +``` +📅 第____周回顾 (____年____月____日) + +🏆 本周突破 + - ________________________________ + - ________________________________ + - ________________________________ + +⚠️ 薄弱环节 + - ________________________________ + - ________________________________ + +🎯 下周目标 + - ________________________________ + - ________________________________ + +🧪 自测挑战(计时!) + □ Speed Drill 挑战 3: 文本对象连击 → 用时: ____ + □ Speed Drill 挑战 4: 重命名风暴 → 用时: ____ + □ Code Golf 场景 5: 删除 console.log → 按键数: ____ + +📊 本周 stats + 练习天数: ____/7 + Speed Drill 新纪录: ____ + Code Golf 新纪录: ____ + +💬 一句话心得: ________________________________ +``` diff --git a/challenges/speed-drill.md b/challenges/speed-drill.md index 96ec4df..2d79be9 100644 --- a/challenges/speed-drill.md +++ b/challenges/speed-drill.md @@ -4,7 +4,7 @@ ## 挑战 1:hjkl 盲打 -**目标**:在 `01-basics/practice.ts` 中,用 `j/k` 从第 1 行移动到第 50 行再回到第 1 行。 +**目标**:在 `01-basics/practice.ts` 中,用 `j/k` 从第 1 行移动到最后一行再回到第 1 行。 | 日期 | 时间 | 出错次数 | 备注 | |------|------|----------|------| diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..d8d7aab --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "ESNext", + "moduleResolution": "bundler", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "noUnusedLocals": false, + "noUnusedParameters": false + }, + "include": [ + "01-basics/**/*.ts", + "02-motions/**/*.ts", + "03-operators/**/*.ts", + "04-zed-superpowers/**/*.ts", + "05-advanced/**/*.ts", + "06-integration/**/*.ts", + "challenges/**/*.ts" + ] +}