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.
The mental shift: operator + text object
Section titled “The mental shift: operator + text object”Every copy is two parts:
- The operator — what to do.
yfor yank. (Later:dto delete,cto change. Same grammar, different verb.) - 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 targets you’ll actually use
Section titled “The targets you’ll actually use”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 this | Press | Read it as |
|---|---|---|
| The word under the cursor | yiw | yank inner word |
| The word plus its trailing space | yaw | yank a word |
Text inside "…" | yi" | yank inside quotes |
Text inside (…) / {…} / […] | yi( yi{ yi[ | yank inside brackets |
| Text inside an HTML/JSX tag | yit | yank inside tag |
| The whole current line | yy | yank line |
| Three lines, starting here | 3yy | yank 3 lines |
| From cursor to end of line | y$ | 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:
ivsa—iis inner (just the contents),ais around (contents plus the surrounding whitespace or delimiters).yiwgrabsword;yawgrabswordwith its space, handy when you’re about to paste it elsewhere.tvsf—tstops till the character (exclusive),ffinds it and includes it.yt;leaves the;behind;yf;takes it with you.
Practice in the playground
Section titled “Practice in the playground”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.
Esc → normal mode. Each challenge checks the unnamed register after you yank.
- Yank the word
greeting— put the cursor on it and pressyiw.yiw = yank inner word
yiw
- Yank what is *inside* the quotes with
yi".yi" = yank inside the quotes (contents only)
yi"
- Yank the arguments inside the parens with
yi(.yi( = yank inside ()
yi(
- Yank the whole
returnline withyy(linewise).yy = yank the entire line, including indentation
yy
- From the
functionline, yank 3 lines with3yy.3yy = yank this line and the two below it
3yy
- Fallback drill: select the first line with
Vthen pressy.V = linewise visual mode; y then yanks the selection
Vy
When to drop to visual mode
Section titled “When to drop to visual mode”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.
| Key | Selects | Then |
|---|---|---|
v | character-wise (grow with motions) | y to yank |
V | whole lines | y to yank |
Ctrl-v | a 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.
A quick drill
Section titled “A quick drill”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.
-
Cursor on
greeting. Pressyiw, then move to a blank spot andpto paste. You copied a word without touching the boundary. -
Cursor inside the
"…"string. Pressyi", thenp. You got the contents, no quotes. -
Cursor inside
(a, b). Pressyi(. Thereg "chip now readsa, b. -
Anywhere on the
returnline, pressyy(the chip shows anLWbadge — linewise). Then3yyfrom thefunctionline to grab the whole body. -
Now the fallback: press
Von the first line to select it line-wise, theny. Same result asyyhere — 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 likeiw,i",i(, or a whole line withyy) — 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.