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 places the copy below.
ddpIncorrect. dd removes the original before p pastes, so it is not a duplicate pair.
Incorrect. dd removes the original before p pastes, so it is not a duplicate pair.
yyddIncorrect. yanking followed by dd deletes the current line.
Incorrect. yanking followed by dd deletes the current line.
ppIncorrect. pp pastes an existing register twice but does not first copy the current line.
Incorrect. pp pastes an existing register twice but does not first copy 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操作 / 一時ファイル
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.