Files
vimx/challenges/code-golf.md
T
fukunee e8dfa0e2f1 Add Vim exercises, cheatsheet, and project polish
Add code golf challenges for Vim practice, a weekly review template, and
extend the cheatsheet with high-frequency commands. Fix the calculator
`multiply` implementation and correct a logger import path.
2026-05-31 23:01:37 +08:00

2.9 KiB
Raw Blame History

🏌️ Code Golf — 代码高尔夫

用最少的按键完成编辑任务。记录你的按键数,挑战用更少的按键完成!

规则

  • 只能用 Vim 快捷键,不能使用鼠标
  • 记录按键数(不包括撤销的 u)
  • 每次完成后在表格填入你的最佳成绩
  • 📁 每个场景都有对应的 .ts 练习文件在 challenges/ 目录下,直接打开即可练习

场景 1:函数签名修改

起始代码:

function greet(name: string): string {
  return "Hello, " + name;
}

目标代码:

function sayHelloTo(firstName: string, lastName: string): string {
  return `Hello, ${firstName} ${lastName}!`;
}
日期 按键数 操作日志

场景 2:对象属性重排

起始代码:

const user = {
  id: 1,
  name: "Alice",
  email: "alice@example.com",
  age: 30,
};

目标代码:

const user = {
  name: "Alice",
  email: "alice@example.com",
  age: 30,
  id: 1,
};
日期 按键数 操作日志

场景 3:批量加注释

起始代码:

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;
}

💡 提示:用宏!qa → 在第一行编辑 → j → q → @a

日期 按键数 操作日志

场景 4:数组转对象

起始代码:

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"];
日期 按键数 操作日志

场景 5:删除所有 console.log

起始代码:

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 process(): void {
  const a = doThing();
  const b = doOtherThing();
  return b;
}

💡 提示:用 g l 选中所有 console.log 行!

日期 按键数 操作日志