Learn Vim / How to Duplicate a Line in Vim

How to Duplicate a Line in Vim

The answerPress yy then p — copy the line, paste it below. Two keystrokes… well, three.

Try it on a real buffer

You need two loaves. You're on the bread line — yank it with yy, then press p to paste it below.

inventory:
- rope
- torch
- bread
- map

Canonical solution: yy p · target: 3 keystrokes — the fewest that solve it (every keypress counts).

Why it works

p pastes after the cursor (below, for whole lines); P pastes before. yy + p is the classic duplicate-line combo.

Variations

KeysWhat it does
yypduplicate the current line
yyPduplicate above instead
:t.duplicate via ex command
V y pvisual-select, copy, paste
▶ live vim buffertarget 3 keystrokes
You need two loaves. You're on the bread line — yank it with yy, then press p to paste it below.

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

Sign in free to practice →

Keep going