In vi normal mode, place the cursor on the line to remove.
Delete the entire line in one operation.
Which command should be used?
dd deletes the complete current line and stores the deleted text in a register, so it can be pasted with p.
Detailed explanation
yyIncorrect. yy yanks the line without deleting it.
Incorrect. yy yanks the line without deleting it.
ccIncorrect. cc changes the line and enters insert mode.
Incorrect. cc changes the line and enters insert mode.
dwIncorrect. dw deletes a word-sized motion from the cursor.
Incorrect. dw deletes a word-sized motion from the cursor.
ddCorrect. dd deletes the current line.
Correct. dd deletes the current line.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp); printf 'keep1\ndelete\nkeep2\n' >"$tmp"; vim -Nu NONE -n -es "$tmp" +'normal gg jdd' +wq; cat "$tmp"; rm -f "$tmp"Expected result
keep1
keep2Key points
- d is the delete operator
- dd operates on a whole line
- Deleted text enters a register
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.