1784314466

Vim From Scratch: The Motions That Change How You Code Forever


If you've ever opened Vim by accident, typed a bunch of letters in a panic, and closed the terminal (or worse, got stuck in there for ten minutes), you're not alone. Almost every programmer has that story. But there's a moment, once you get past that initial trauma phase, when something clicks: you realize you're not just editing text anymore, you're *talking* to the editor in its own language. And after that, there's no going back. This isn't about memorizing a hundred shortcuts. It's about understanding a handful of motions that, on their own, already change the way you write code. You'll pick up the rest over time, just by using it. ## The first click: Vim thinks in sentences, not keys The initial confusion everyone runs into is thinking Vim is a pile of random shortcuts. It isn't. Vim has a grammar. You combine a **verb** (what to do) with an **object** (where to do it). Deleting a word is `dw` — *delete* plus *word*. Deleting to the end of the line is `d$`. Copying an entire paragraph is `yap`. Once that logic settles into your head, you stop memorizing commands and start *composing* them, like sentences. That's why experienced Vim users seem to be doing magic on screen: they don't know more shortcuts than you, they just already understand the sentence they're forming before they type it. ## The four steps that replace the arrow keys Forget the arrow keys. Seriously, take your hand off them. Vim's basic motions sit right under your fingers, on the home row: `h` moves left, `l` moves right, `j` moves down (think of an arrow pointing down hidden in the letter) and `k` moves up. At first it feels slower than using the arrows, because your hands don't trust this new map yet. After three or four days of stubborn use, it becomes automatic, and you realize you never have to leave the typing position to navigate a file again. ## Moving by words, not by letters Here's the first motion that really changes the game. `w` jumps to the start of the next word. `b` jumps back to the start of the previous word. `e` jumps to the end of the current word (or the next one, if you're already at the end of one). Picture a line like this: ``` const userName = getUserFromDatabase(id); ``` With `w`, you hop through `const`, `userName`, `=`, `getUserFromDatabase` and `(id);` in single jumps, each keypress landing you at the start of the next word. That's a lot faster than holding the right arrow and counting letters in your head. And when you pair it with a verb, like `dw` to delete the word under the cursor, the speed gain becomes even clearer: one verb key plus one motion key, and the word is gone. There's an uppercase variant worth knowing: `W`, `B` and `E` make the same kind of jump, but ignore punctuation — they treat `getUserFromDatabase(id);` as a single chunk instead of stopping at every parenthesis or semicolon. Handy when you're dealing with a line full of symbols and want to cross it fast without stopping at each one. ## Start and end of a line, effortlessly `0` (zero) puts the cursor on the very first column of the line, literally, ignoring any whitespace. `^` puts it on the first non-blank character — much more useful day to day, since code usually has indentation, and you almost always want the start of the content, not the absolute start of the line. `$` moves to the end of the line. Notice how much everyday editing this already solves: `d$` deletes from the cursor to the end of the line, `y$` copies that same stretch, `c$` deletes it and drops you straight into insert mode ready to type whatever comes next. ## Flying through the whole file When the file is large, `gg` takes you to the first line and `G` to the last one. Need a specific line? Type the number first: `42G` takes you straight to line 42, no scrolling with the mouse or visually counting lines. There's also `Ctrl+d` and `Ctrl+u`, which scroll down and up half a screen at a time — better than `Page Down` because they keep you oriented in the file's context, since the screen doesn't jump all at once. ## The motion nobody tells you about upfront: searching within the line This one is usually the turning point for people who already know the basics. `f` plus a character jumps the cursor to the next occurrence of that character on the current line. For example, in a line like: ``` function calculateTotal(price, tax, discount) { ``` If the cursor is at the start and you type `f(`, it jumps straight to the opening parenthesis. Want to delete everything between the parentheses? `f(` to get there, then `di(` — *delete inside parentheses* — clears the entire inner content, keeping the parentheses in place. That replaces minutes of manual selection with three or four keystrokes. `t` works similarly, but stops *before* the searched character instead of on top of it. And `;` repeats the last `f` or `t` search, `,` repeats it in the opposite direction. Once you get the hang of combining `f` with `d`, `c` or `y`, editing code inside parentheses, quotes and brackets becomes almost instant. ## Repeating the last action with a single dot The `.` command repeats your last change. It sounds small, but it's one of the motions that saves the most time in practice. Say you deleted a word with `dw`. If you need to delete the next word too, you don't repeat the whole command — you just hit `.` and Vim redoes the last edit wherever the cursor is now. This gets even more powerful when you move the cursor with `w`, `f` or `/` (search) between repetitions. You edit one spot, jump to the next similar one, hit `.`, jump again, hit `.` again — and suddenly you've made five identical edits in five different places in the file in a matter of seconds. ## Visual mode: when you actually need to see what you're selecting Not everything needs to be done blind by combining verb and motion. `v` enters character-wise visual mode, `V` enters line-wise visual mode, and `Ctrl+v` enters block visual mode (great for editing several lines in the same column at once, like adding `//` at the start of a block of comments). You select by moving with the same `h j k l w b e f t`, then apply a command: `d` deletes, `y` copies, `c` deletes and drops you into insert mode. Block visual mode specifically is the kind of feature that seems minor until the day you need to comment out fifteen lines of code at once and realize you can do it in four keystrokes, no plugin required. ## Why it's worth the effort None of these motions, on their own, seems revolutionary. The real shift happens when they add up: you stop thinking "move the cursor here, then hit delete" and start thinking in full editing sentences, composed on the fly, without stopping to plan. `ciw` replaces the entire word under the cursor. `dap` deletes the whole paragraph, along with the blank line after it. `yi"` copies whatever's inside quotes. Vim isn't fast because it has magic shortcuts. It's fast because it turns text editing into a language you speak with your hands, without having to think. And like any language, the beginning is awkward and slow — but after two or three weeks of real use, on real projects, you'll look back and won't remember how you ever coded any other way.

(1) Comments
exterminator
exterminator
1784315437

If you're interested in discussing this topic further, we can set up a chat room to explore this and other programming-related topics in greater depth. If you like the chat format for learning and sharing information, feel free to join us.


Welcome to Chat-to.dev, a space for both novice and experienced programmers to chat about programming and share code in their posts.

About | Privacy | Donate
[2026 © Chat-to.dev]