In vi, the cursor is on a line that should remain in place.
Copy that line immediately below the current line.
Which command is correct?
yy copies the current line into a register, and p pastes it after the current line.
Detailed explanation
ddpIncorrect. dd deletes the line before p pastes it, so this moves rather than duplicates it.
Incorrect. dd deletes the line before p pastes it, so this moves rather than duplicates it.
yyIncorrect. yy only copies the line.
Incorrect. yy only copies the line.
yypCorrect. yy yanks the line and p pastes the copy below it.
Correct. yy yanks the line and p pastes the copy below it.
pIncorrect. p alone pastes the previous register and does not copy the current line.
Incorrect. p alone pastes the previous register and does not copy the current line.
Try it yourself
An example you can run in a temporary verification environment.
printf 'alpha
beta
gamma
' > sample.txt
vim -Nu NONE -n -es sample.txt <<'VIM'
2
normal! yyp
wq
VIM
cat sample.txtExpected result
alpha
beta
beta
gammaKey points
- Yank versus delete
- The paste position of p
- Normal-mode commands
Notes
- Environment: Vim 9.x / 個人設定なし
- 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.