In vi normal mode, a line was accidentally deleted.
Undo exactly that one change and return to the state before deletion.
Which key should be pressed?
Normal-mode u undoes the most recent change. The period repeats a change, while Ctrl-r redoes an undone change.
Detailed explanation
.Incorrect. The period repeats the last change.
Incorrect. The period repeats the last change.
Ctrl-gIncorrect. Ctrl-g displays status information.
Incorrect. Ctrl-g displays status information.
uCorrect. u undoes the most recent change.
Correct. u undoes the most recent change.
Ctrl-rIncorrect. Ctrl-r redoes an undone change rather than undoing it.
Incorrect. Ctrl-r redoes an undone change rather than undoing it.
Try it yourself
An example you can run in a temporary verification environment.
printf 'one\ntwo\n' > sample.txt; vim -Nu NONE -n -es sample.txt -c 'normal! dd' -c 'normal! u' -c 'wq'; cat sample.txtExpected result
one
twoKey points
- u is undo
- . repeats a change
- Ctrl-r is redo
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.