跳到正文
DEV Community· Spartan Rich·· 4 小時前AI 評分54

如何學習 Vim,並真正記住指令

How to Learn Vim (and Actually Remember the Commands)

AI 導讀

這篇指南提出一套循序學習 Vim 的方法,先掌握少量常用指令,再靠實際編輯和間隔複習把操作記熟。作者建議理解操作符與移動命令、文本對象的組合,每日完成一項真實編輯任務,並把常忘的指令製成複習卡。作者亦介紹自建的 AI 學習 app Recl,會整理已儲存內容,並按 1、3、7、14、30 和 60 天的間隔重新呈現。

正文

Most people who try Vim quit in the same week. They run vimtutor, get through it in half an hour, feel pretty good, and then open a real file on Monday and can't remember how to delete a word. So they reach for the arrow keys, then the mouse, then VS Code.

I don't think the problem is Vim being hard. It's that people learn the commands once and never see them again until they need them under pressure.

If you're searching "how to learn Vim," you'll find cheat sheets with 150 commands on them. Skip those for now. This post is about learning a small set well enough that your fingers know it, and then growing it slowly.

Start with vimtutor, but only once

vimtutor ships with Vim. Type it in a terminal and you get a plain text lesson you edit as you go. It covers moving around, deleting, changing text, undo, search and saving. It takes about 30 minutes.

Do it once. Then stop reading tutorials for a while. The tutor gives you the vocabulary, and the next part is getting that vocabulary to stick, which a second read through won't do.

Learn the grammar, then memorize less

The thing that made Vim click for me was realizing most commands are sentences. There's an operator (what to do), and a motion or text object (what to do it to).

d is delete. w is a word. So dw deletes a word. c is change, i" means "inside quotes," so ci" wipes whatever is between the quotes and drops you into insert mode. y is yank (copy), ip is "inner paragraph," so yip copies the paragraph you're in.

Once you know five operators and ten motions, you have dozens of commands you never had to learn one by one. That's why the giant cheat sheets are a trap. They list combinations, and you only need the parts.

A starter set that covers a surprising amount of daily editing:

  • Operators: d, c, y, > and <
  • Motions: w, b, e, 0, $, gg, G, f{char}, t{char}
  • Text objects: iw, aw, i", i(, ip, it (inside a tag, handy for HTML)
  • The dot command, ., which repeats your last change

The dot command deserves its own line. Change one word with ciw, type the new word, hit Escape, move to the next one and press .. That pattern alone replaces a lot of find-and-replace.

Use it on real work, just a little

The worst way to learn Vim is to switch everything over on a deadline day. The second worst is practicing on toy files you don't care about.

What works better is one real task a day in Vim. Edit your .gitconfig, write a commit message, fix a YAML file on a server over SSH. If you live in VS Code or a JetBrains IDE, install the Vim plugin for it (VSCodeVim and IdeaVim are the common ones) and keep it on for an hour a day. You get the motions without losing your debugger.

You will be slower for a couple of weeks. That's normal and it passes.

Turn the commands you keep forgetting into review cards

Here's the part most guides leave out. You'll find yourself looking up the same five things over and over. For me it was :%s/old/new/gc, how to record a macro, and the difference between t and f.

Every time you look something up, write it down as a question you could be quizzed on:

How do you replace "foo" with "bar" in the whole file, confirming each one?
:%s/foo/bar/gc

How do you record a macro into register q and replay it 10 times?
qq, do the edits, q, then 10@q

Then review those cards on a growing schedule: the next day, a few days later, a week, two weeks. That's spaced repetition, and it's the same idea Anki is built on. Each time you recall a command correctly, the gap before you see it again gets longer, so you spend almost no time on the ones you know and more on the ones that keep slipping.

I wrote up the scheduling math in How to Implement Spaced Repetition (SM-2) in JavaScript if you want to roll your own.

Keep the deck small. Twenty cards you actually use beat two hundred you saw on a cheat sheet.

Keep the good videos from disappearing

A lot of real Vim learning happens through other people's screencasts. Someone does something in three keystrokes that would take you thirty, you pause, rewind, and think "I need to remember that." Then it goes into Watch Later and that's the end of it.

This is the problem I built Recl for. You share a video, reel, podcast or article to it from your phone or the Chrome extension, and it writes a summary of the key points, with timestamps for videos. It sorts saves into topics, so all your Vim and terminal stuff lands together, and it brings each save back 1, 3, 7, 14, 30 and 60 days later.

Recl feed showing saved videos and articles sorted by topic

So the talk where someone explains text objects shows up again next week, right when you've half forgotten it. You can also ask it things like "what did I save about Vim macros?" and get an answer pulled from your own saves, with the sources.

It won't press the keys for you. You still have to practice. But it stops the good stuff from vanishing.

Add one thing a week

Once the starter set feels automatic, add one new idea per week. A sensible order: visual block mode (Ctrl-v) for editing columns, then registers, then macros, then splits and buffers, then a bit of .vimrc config. If you want to go further, Drew Neil's book Practical Vim is still the best next step I know of.

Resist the urge to install 40 plugins in week one. Every plugin is something else to learn, and most of what people want from plugins is already in stock Vim.

What a normal week looks like

Ten minutes of card review in the morning. One real editing task in Vim each day. One new command or concept on Monday, written down as a card. That's it.

It's slower than binge-reading a cheat sheet, but a month in you'll stop thinking about the keys, which is the whole point of learning Vim in the first place.


I build Recl, an AI learning app that saves your videos, reels, podcasts and articles, summarizes them, sorts them into topics, and uses spaced repetition so you remember what you learned.

來源:DEV Community · dev.to