In vi normal mode, duplicate the current line directly below itself.
Use yank and paste without editing the contents.
Which key sequence is appropriate?
yy yanks the current line and p pastes linewise content below the current line.
Detailed explanation
yypCorrect. yy copies the line and p places the copy below.
Correct. yy copies the line and p inserts the copy below it.
ddpIncorrect. dd removes the original before p pastes, so it is not a duplicate pair.
Incorrect. dd removes the original before the paste, so it is not a duplicate operation.
yyddIncorrect. yanking followed by dd deletes the current line.
Incorrect. The final dd removes the original and can replace the register contents.
ppIncorrect. pp pastes an existing register twice but does not first copy the current line.
Incorrect. pp pastes an existing register twice without first copying the current line.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp); printf 'alpha\nbeta\n' >"$tmp"; vim -Nu NONE -n -es "$tmp" +'normal ggyyp' +wq; cat "$tmp"; rm -f "$tmp"Expected result
alpha
alpha
betaKey points
- yy yanks a line
- p pastes below
- The original line remains
Notes
- Environment: Vim 9.x互換のvi操作 / 一時ファイル
- Use a temporary file and harmless edits when testing vi commands.
- Confirm the behavior on the target vi/Vim implementation.
Foundation review
Place the operation
Copying preserves the original; deleting before pasting changes the operation into a move or replacement.
Check the side effect
Run yy followed by p on a disposable line and count the resulting lines.