← 返回日报
精读 预计 3 分钟

Learn Vim motions with an ice-cream van

摘要

《Learn Vim motions with an ice-cream van》是一款在线小贩游戏。游戏中光标代表小贩,文本区域是小镇。玩家按 h j k l 驱动小贩到达顾客位置,匹配按键达到 “清扫” 条件或打破纪录赢得 Wizard 等级。关卡地图展示每个关卡教授的少量 Vim 动作(含名称与功能)。全流程包括基础教学、按键展示面板(实时回显按键)、重复计数(3j 等)、多键组合(等待第二键如 f x)、撤消(u/Ctrl + r)、模式切换(Normal/Insert/Visual)和注册表宏("a yy 等)。完整列出所有教学动作的参考表:移动类(h j k l 0^$ w/b/e W/B/E gg/G fx/Fx tx/Tx ;/, 3j)、编辑类(x r c dd/yy dw/de/d$ p/P xp di"/di ( da. u/Ctrl + r)、插入类(i/a I/A o/O cc/C s ciw/ci"Esc)、可视类(v/V Ctrl + v d/y/c o)、搜索类(/text n/N)、寄存器宏("a yy @a … @@)。新手先读完参考表。

荐读理由

游戏关卡教 Vim 移动、编辑、搜索、插入等关键 motions 的具体 keystroke 与计数用法,每一步都是可直接抄到项目里的精确操作

原文

~/vim-scoops

$./vim-scoops --learn▉

Learn vim motions with an ice-cream van.

The van is your cursor and the town is your text. Learn Vim motions the tasty way.

Play the full game

Try it: one quick level

Drive the van onto the customer with h j k l.

Play the full game →

How to play

Learn the basics, then you're going.

Pick a route

Each level on the town map teaches a small set of motions, shown as badges with what they do.

Drive the van

Press keys to move, with no mouse or arrow keys. The panel echoes every key you press so you can see your motions.

Serve under par

Reach every customer. Match the keystroke par to clear it; beat it to earn a Wizard rank.

New to vim? Read this first

Vim edits text with the keyboard alone. Instead of clicking or holding an arrow key, you press single keys that move the cursor precisely, such as one word forward or to the end of a line. Those keys are called motions, and they are what make experienced vim users fast. This game teaches them one at a time.

You're always in Normal mode here, so every key is a command. Put a number in front to repeat (3j moves down three), and if a key seems to do nothing it's usually waiting for a second key, like f then the letter to jump to. The panel tells you when it's waiting.

Motion & command reference

Every motion the game teaches. Each level only shows the few it needs.

Moving

h j k l Move left, down, up, right
0 ^ $ Line start, first shop, line end
w / b / e Hop forward / back / to block end
W B E Same, but over punctuation too
gg / G Jump to the top / bottom row
fx / Fx Fly right / left onto letter x
tx / Tx Pull up before / after letter x
; / , Repeat the last f/t hop, fwd / back
3j A count before a key repeats it

Editing

x Delete the character under the cursor
rc Replace that character with c
dd / yy Cut / copy the whole line
dw de d$ Delete to a motion (pair d with a move)
p / P Paste after / before the cursor
xp Swap two neighbours
di" di( Delete inside quotes/brackets (da includes them)
. Repeat your last change
u / Ctrl+r Undo / redo

Insert mode

i / a Type before / after the cursor
I / A Type at the line start / end
o / O Open a line below / above
cc / C Change the line / to end of line
s Delete a char and start typing
ciw ci" Change a word or the text inside quotes
Esc Back to normal mode

Visual mode

v Highlight a range as you move
V Highlight whole lines
Ctrl+v Highlight a column (block)
d / y / c Delete / copy / change the highlight
rc Replace every highlighted char with c
o Jump to the other end

Search

/textEnter Search and jump to the next match
n / N Next / previous match
* Search the word under the cursor

Registers & macros

"ayy Copy the line into bin a (any a-z)
"ap Paste from bin a
qa … q Record keys into bin a, then stop
@a Replay bin a (count works: 3@a)
@@ Replay the last routine
Hacker News · 9 赞 · 1 评 讨论 → 阅读原文 →

这条对你有帮助吗?