nerdexam
Linux_Foundation

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!.

Submitted by fatima_kr· May 4, 2026Linux Fundamentals

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)
  • A
    91% (53)
  • B
    2% (1)
  • C
    3% (2)
  • D
    3% (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!`.

A:q!Correct

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.

BZZ

The `ZZ` command is used to save the file and then quit the vi/vim editor.

C:wq!

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.

D:exit

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

#vi/vim#Text Editing#Command Mode#File Operations

Community Discussion

No community discussion yet for this question.

Full LFCA Practice