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. Put the cursor on the “- bread” line, yank it with yy, then press p to paste it below.

inventory:
- rope
- torch
- bread
- map

Canonical solution: yy p (on the bread line) · par: 5 keystrokes (vimgolf rules — 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

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.

Practice free — no signup →

Keep going