Add VimX learning project for Zed Vim mode mastery
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
# 第四阶段:Zed 独有超能力
|
||||
|
||||
> 目标:掌握 Zed Vim 模式独有的 Tree-sitter、LSP 和多光标能力。
|
||||
|
||||
## 任务清单
|
||||
|
||||
### 任务 1:LSP 导航(Language Server Protocol)
|
||||
- [ ] `g d` — 跳转到定义(Go to Definition)
|
||||
- [ ] `g D` — 跳转到声明(Go to Declaration)
|
||||
- [ ] `g y` — 跳转到类型定义(Go to Type Definition)
|
||||
- [ ] `g I` — 跳转到实现(Go to Implementation)
|
||||
- [ ] `g A` — 查找所有引用(Go to All references)
|
||||
- [ ] `c d` — 重命名符号(Change Definition)
|
||||
- [ ] `g .` — 打开代码动作菜单
|
||||
- [ ] `g h` — 显示悬停信息(hover)
|
||||
- [ ] `g ]` / `] d` — 下一个诊断(错误/警告)
|
||||
- [ ] `g [` / `[ d` — 上一个诊断
|
||||
- [ ] `g s` — 当前文件内搜索符号
|
||||
- [ ] `g S` — 全项目搜索符号
|
||||
|
||||
### 任务 2:Tree-sitter 语法导航
|
||||
- [ ] `] m` / `[ m` — 下一个/上一个方法
|
||||
- [ ] `] M` / `[ M` — 下一个/上一个方法结束
|
||||
- [ ] `] ]` / `[ [` — 下一个/上一个代码节(class/section)
|
||||
- [ ] `] /` / `[ /` — 下一个/上一个注释
|
||||
- [ ] `[ x` — 选择更大的语法节点
|
||||
- [ ] `] x` — 选择更小的语法节点
|
||||
|
||||
### 任务 3:Tree-sitter 文本对象
|
||||
- [ ] `a c` — 整个类/定义(around class)
|
||||
- [ ] `i c` — 类/定义内部(inside class)
|
||||
- [ ] `a f` — 整个函数
|
||||
- [ ] `i f` — 函数内部
|
||||
- [ ] `g c` — 注释
|
||||
- [ ] `i a` — 参数/列表项
|
||||
- [ ] `a a` — 参数/列表项+尾部逗号
|
||||
- [ ] `a t` — HTML 标签及内容
|
||||
- [ ] `i t` — HTML 标签内部
|
||||
- [ ] `a I` — 当前缩进级别+前后各一行
|
||||
- [ ] `a i` — 当前缩进级别+前一行
|
||||
- [ ] `i i` — 当前缩进级别
|
||||
|
||||
### 任务 4:多光标操作
|
||||
- [ ] `g l` — 添加光标选中下一个相同单词
|
||||
- [ ] `g L` — 添加光标选中上一个相同单词
|
||||
- [ ] `g a` — 为每个相同单词添加可视选区
|
||||
- [ ] `g >` / `g <` — 跳过当前选择,选下一个/上一个
|
||||
- [ ] `g A` — 在选中的每一行末尾添加光标(可视模式)
|
||||
- [ ] `g I` — 在选中的每一行开头添加光标(可视模式)
|
||||
|
||||
### 任务 5:Git 集成
|
||||
- [ ] `] c` / `[ c` — 下一个/上一个 Git 变更
|
||||
- [ ] `d o` — 展开 diff hunk
|
||||
- [ ] `d p` — 还原变更
|
||||
|
||||
### 任务 6:Pane 管理
|
||||
- [ ] `g /` — 打开项目搜索
|
||||
- [ ] `g <space>` — 打开当前搜索结果
|
||||
- [ ] `Ctrl+w <space>` — 在分割窗格打开搜索结果
|
||||
- [ ] `Ctrl+w g d` — 在分割窗格跳转到定义
|
||||
- [ ] `Ctrl+w g D` — 在分割窗格跳转到类型定义
|
||||
|
||||
### 任务 7:插入模式增强
|
||||
- [ ] `Ctrl+x Ctrl+o` — 打开补全菜单
|
||||
- [ ] `Ctrl+x Ctrl+l` — 打开代码动作菜单
|
||||
|
||||
### 任务 8:实战
|
||||
打开 `superpowers.ts`:
|
||||
- [ ] 用 `] m` / `[ m` 在方法间跳转
|
||||
- [ ] 用 `] ]` / `[ [` 在类/接口间跳转
|
||||
- [ ] 用 `g d` 跳到某个函数的定义
|
||||
- [ ] 用 `g A` 查看某个变量的所有引用
|
||||
- [ ] 用 `g l` 选中下一个相同单词,批量修改
|
||||
- [ ] 用 `d a c` 删除整个类
|
||||
- [ ] 用 `c i f` 修改函数体
|
||||
|
||||
## 自查标准
|
||||
- [ ] 能用 `] m` / `[ m` 代替鼠标滚轮浏览代码
|
||||
- [ ] 能用 `g d` 和 `g A` 理解代码调用关系
|
||||
- [ ] 能用 `g l` 批量修改变量名
|
||||
- [ ] 能用 Tree-sitter 文本对象精准操作语法单元
|
||||
@@ -0,0 +1,103 @@
|
||||
// ============================================================
|
||||
// 第四阶段练习文件 — Zed 超能力
|
||||
// ============================================================
|
||||
//
|
||||
// 练习 LSP 导航:
|
||||
// - 光标放在 fetchUsers 上,按 g d 跳转到定义
|
||||
// - 光标放在 User 上,按 g A 查看所有引用
|
||||
// - 光标放在 processUsers 上,按 c d 重命名
|
||||
//
|
||||
// 练习 Tree-sitter 导航:
|
||||
// - 用 ] m / [ m 在方法间跳转
|
||||
// - 用 ] ] / [ [ 在类/接口间跳转
|
||||
// - 用 g c 选择注释
|
||||
//
|
||||
// 练习多光标:
|
||||
// - 光标放在 user 上,按 g l 选中所有 user
|
||||
// - 然后修改它们看看多光标效果
|
||||
//
|
||||
// ============================================================
|
||||
|
||||
interface Address {
|
||||
street: string;
|
||||
city: string;
|
||||
zipCode: string;
|
||||
}
|
||||
|
||||
interface User {
|
||||
id: number;
|
||||
name: string;
|
||||
email: string;
|
||||
isActive: boolean;
|
||||
address?: Address;
|
||||
tags: string[];
|
||||
}
|
||||
|
||||
class UserService {
|
||||
private users: User[] = [];
|
||||
|
||||
async fetchUsers(): Promise<User[]> {
|
||||
// TODO: Connect to API
|
||||
const response = await fetch("/api/users");
|
||||
const data = await response.json();
|
||||
this.users = data;
|
||||
return this.users;
|
||||
}
|
||||
|
||||
findUserById(id: number): User | undefined {
|
||||
return this.users.find((user) => user.id === id);
|
||||
}
|
||||
|
||||
getActiveUsers(): User[] {
|
||||
return this.users.filter((user) => user.isActive);
|
||||
}
|
||||
|
||||
addTagToUser(userId: number, tag: string): void {
|
||||
const user = this.findUserById(userId);
|
||||
if (user) {
|
||||
user.tags.push(tag);
|
||||
}
|
||||
}
|
||||
|
||||
removeTagFromUser(userId: number, tag: string): void {
|
||||
const user = this.findUserById(userId);
|
||||
if (user) {
|
||||
user.tags = user.tags.filter((t) => t !== tag);
|
||||
}
|
||||
}
|
||||
|
||||
// 试试用 da f 删除整个方法,用 ci f 修改方法体
|
||||
getUsersByCity(city: string): User[] {
|
||||
return this.users.filter((user) => user.address?.city === city);
|
||||
}
|
||||
}
|
||||
|
||||
class NotificationService {
|
||||
sendEmail(user: User, subject: string, body: string): void {
|
||||
// Send email logic
|
||||
console.log(`Sending email to ${user.email}: ${subject}`);
|
||||
}
|
||||
|
||||
notifyActiveUsers(users: User[], message: string): void {
|
||||
const activeUsers = users.filter((user) => user.isActive);
|
||||
activeUsers.forEach((user) => {
|
||||
this.sendEmail(user, "Notification", message);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Main application
|
||||
async function main(): Promise<void> {
|
||||
const userService = new UserService();
|
||||
const notificationService = new NotificationService();
|
||||
|
||||
const users = await userService.fetchUsers();
|
||||
const activeUsers = userService.getActiveUsers();
|
||||
|
||||
notificationService.notifyActiveUsers(users, "Welcome back!");
|
||||
|
||||
console.log(`Total users: ${users.length}`);
|
||||
console.log(`Active users: ${activeUsers.length}`);
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
Reference in New Issue
Block a user