Skip to content

Selection & Yanking

You’re in Zed’s vim mode and you want to copy a word. Your hand reaches for the old reflex: double-click to select, then Cmd+C. It half-works, it feels clumsy, and it breaks your flow. That reflex is select-then-copy — and in Vim it’s backwards.

In a normal editor you select first, then act: highlight a region, then copy it. Vim flips the order. You say the verb first, then name what to copy — no highlighting step at all. The verb is y (yank, Vim’s word for copy). What follows is a tiny description of the target.

y i w
│ │ └─ noun: "word"
│ └──── modifier: "inner"
└─────── verb: yank (copy)

Read yiw as one thought: “yank inner word.” Put your cursor anywhere on a word, press those three keys, and the whole word is in your clipboard. You never selected it. You described it.

Every copy is two parts:

  1. The operatorwhat to do. y for yank. (Later: d to delete, c to change. Same grammar, different verb.)
  2. The target — a motion or a text object that answers “copy what?”

A text object is a named region Vim already understands — a word, the text inside quotes, the contents of a bracket pair. You don’t draw the boundary; you name it and Vim finds the edges. The selection is implicit.

So the question to train yourself to ask isn’t “what do I drag over?” It’s “copy WHAT?” — and the answer is always a text object or a motion.

The pattern is y + a target. The target is either an object (i = inner / a = around) or a motion (t, f, $). These cover the vast majority of real copies:

Copy thisPressRead it as
The word under the cursoryiwyank inner word
The word plus its trailing spaceyawyank a word
Text inside "…"yi"yank inside quotes
Text inside (…) / {…} / […]yi( yi{ yi[yank inside brackets
Text inside an HTML/JSX tagyityank inside tag
The whole current lineyyyank line
Three lines, starting here3yyyank 3 lines
From cursor to end of liney$yank to line end
From cursor up to (not incl.) the next ;yt;yank till ;
From cursor up to and including the next ;yf;yank find ;

Two distinctions worth burning in early, because they’re the ones people trip on:

  • i vs ai is inner (just the contents), a is around (contents plus the surrounding whitespace or delimiters). yiw grabs word; yaw grabs word with its space, handy when you’re about to paste it elsewhere.
  • t vs ft stops till the character (exclusive), f finds it and includes it. yt; leaves the ; behind; yf; takes it with you.

Put your cursor in the editor, press Esc to make sure you’re in normal mode, then work the challenges. The reg " chip on the right shows what’s currently in your unnamed register — watch it change as you yank.

Practice: yank by naming the target
reg "

Esc → normal mode. Each challenge checks the unnamed register after you yank.

  • Yank the word greeting — put the cursor on it and press yiw.
  • Yank what is *inside* the quotes with yi".
  • Yank the arguments inside the parens with yi(.
  • Yank the whole return line with yy (linewise).
  • From the function line, yank 3 lines with 3yy.
  • Fallback drill: select the first line with V then press y.

Text objects don’t cover everything. Sometimes the region you want isn’t a word, a line, or a balanced delimiter pair — it’s an irregular span only you can see. That’s what visual mode is for: you highlight it by hand, then yank.

KeySelectsThen
vcharacter-wise (grow with motions)y to yank
Vwhole linesy to yank
Ctrl-va rectangular block (column)y to yank

The flow is select, then y — the old reflex, but deliberate. Use it for things like “from here to that random spot three words in,” or a block of aligned columns, where no text object names the boundary cleanly.

Run these in order in the playground above (press Esc first). The goal is to feel the name-it reflex replace the select-it one.

  1. Cursor on greeting. Press yiw, then move to a blank spot and p to paste. You copied a word without touching the boundary.

  2. Cursor inside the "…" string. Press yi", then p. You got the contents, no quotes.

  3. Cursor inside (a, b). Press yi(. The reg " chip now reads a, b.

  4. Anywhere on the return line, press yy (the chip shows an LW badge — linewise). Then 3yy from the function line to grab the whole body.

  5. Now the fallback: press V on the first line to select it line-wise, then y. Same result as yy here — which is exactly the point. When a text object fits, prefer it; save visual mode for the spans that don’t.

The whole lesson in one sentence:

Don’t select-then-copy. Say copy (y), then name what to copy (a text object like iw, i", i(, or a whole line with yy) — and drop to visual mode only when the target is too irregular to name.

Once the verb→noun grammar clicks, it generalizes: swap y for d and you delete the same targets; swap in c and you change them. Same nouns, new verb. That’s the next lesson.