Learn Vim / How to Copy a Word in Vim

How to Copy a Word in Vim

The answerWith the cursor on the word, press yiw — yank inner word. Paste with p.

Try it on a real buffer

Copy the 3rd word of line 10. Jump with 10G, go to the line start with 0, hop two words with 2w, then yank the inner word with yiw. Don't change the file.

nothing to see on line one
line two is just filler
line three keeps the count honest
line four, still scrolling
line five has no treasure
line six is deliberately boring
line seven, keep going
line eight, almost there
line nine, one more
grab the emerald from this line
line eleven, you went too far
line twelve, way too far

Canonical solution: 10G 0 2w yiw · par: 7 keystrokes (vimgolf rules — every keypress counts).

Why it works

Counts multiply motions: 2w = w twice. yiw yanks the “inner word” under the cursor — no trailing space. You'll meet more of these text objects soon.

Variations

KeysWhat it does
yiwcopy the word under the cursor
yawcopy the word plus its space
yecopy to the end of the word
2w yiwhop two words, then copy

Reading about keystrokes doesn't build keystrokes. Try this in a real vim buffer right now — the “The emerald heist” mission takes about a minute.

Practice free — no signup →

Keep going