LFCA · Question #21
When using vi or vim to edit a file, how do you exit without saving?
The correct answer is A. :q! The vi/vim editor uses specific commands to perform actions like exiting, saving, or quitting without saving. To exit the editor without saving any changes, the correct command is :q!.
Question
When using vi or vim to edit a file, how do you exit without saving?
Options
- A:q!
- BZZ
- C:wq!
- D:exit
How the community answered
(58 responses)- A91% (53)
- B2% (1)
- C3% (2)
- D3% (2)
Why each option
The vi/vim editor uses specific commands to perform actions like exiting, saving, or quitting without saving. To exit the editor without saving any changes, the correct command is `:q!`.
The `:q!` command in vi/vim is used to force quit the editor without saving any changes made to the file. The `q` stands for quit, and the `!` forces the action, overriding warnings about unsaved changes.
The `ZZ` command is used to save the file and then quit the vi/vim editor.
The `:wq!` command is used to write (save) the file and then quit the vi/vim editor, forcing the write if the file is read-only.
The `:exit` command is not a standard vi/vim command for quitting; it might be recognized as an alias in some shell environments but not directly within vi/vim for this purpose.
Concept tested: vi/vim editor commands
Source: https://learn.microsoft.com/en-us/cli/azure/reference-group-commands-bash-quick-reference#file-management-commands
Topics
Community Discussion
No community discussion yet for this question.