A vi file was changed, but the changes are no longer wanted.
Exit without modifying the on-disk file.
Which command is appropriate?
:q! discards unsaved changes and exits. The exclamation mark does not universally mean save; its effect depends on the command.
Detailed explanation
:w!Incorrect. :w! writes the changes.
Incorrect. :w! writes the changes.
ZZIncorrect. ZZ saves changes before exiting.
Incorrect. ZZ saves changes before exiting.
:e!Incorrect. :e! discards and reloads but does not exit.
Incorrect. :e! discards and reloads but does not exit.
:q!Correct. :q! abandons changes and exits.
Correct. :q! abandons changes and exits.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp); printf 'original\n' >"$tmp"; vim -Nu NONE -n -es "$tmp" +'normal ggccchanged' +q!; cat "$tmp"; rm -f "$tmp"Expected result
originalKey points
- :q! discards and exits
- :e! discards and reloads
- Command meanings must be checked
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.