nerdexam
CompTIA

LX0-103 · Question #186

While editing a file in vi, an administrator realizes that the wrong file is being changed. Which of the following vi command sequences will allow the administrator to quit without saving any changes?

The correct answer is B. :q!. In vi, :q! is the correct command to quit immediately without saving, forcibly discarding all unsaved changes to the buffer.

GNU and Unix Commands

Question

While editing a file in vi, an administrator realizes that the wrong file is being changed. Which of the following vi command sequences will allow the administrator to quit without saving any changes?

Options

  • A:Q!
  • B:q!
  • C:w!
  • D:wq!

How the community answered

(25 responses)
  • A
    4% (1)
  • B
    92% (23)
  • D
    4% (1)

Why each option

In vi, :q! is the correct command to quit immediately without saving, forcibly discarding all unsaved changes to the buffer.

A:Q!

:Q! uses an uppercase Q which is not a valid vi quit command - vi commands are case-sensitive and :Q! will produce an error.

B:q!Correct

:q! is the standard vi command to quit without saving - the colon enters command-line mode, q instructs vi to quit, and the exclamation mark forces the quit even when unsaved changes exist. This is the definitive method to discard edits and exit the editor immediately.

C:w!

:w! writes and saves the current buffer to disk but does not exit the editor.

D:wq!

:wq! writes the file and then quits, which saves the unwanted changes rather than discarding them.

Concept tested: vi quit without saving command

Source: https://www.vim.org/docs.php

Topics

#vi editor#quit without saving#:q!

Community Discussion

No community discussion yet for this question.

Full LX0-103 Practice