nerdexam
CompTIA

LX0-103 · Question #210

Which of the following sequences in the vi editor saves the opened document and exits the editor? (Choose TWO correct answers.)

The correct answer is A. esc ZZ D. esc :wq!. In vi, both ZZ (typed in normal mode after Esc) and :wq! (a command-line instruction after Esc) write the file and exit the editor.

GNU and Unix Commands

Question

Which of the following sequences in the vi editor saves the opened document and exits the editor? (Choose TWO correct answers.)

Options

  • Aesc ZZ
  • Bctrl :w!
  • Cesc zz
  • Desc :wq!
  • Ectrl XX

How the community answered

(29 responses)
  • A
    90% (26)
  • B
    7% (2)
  • E
    3% (1)

Why each option

In vi, both ZZ (typed in normal mode after Esc) and :wq! (a command-line instruction after Esc) write the file and exit the editor.

Aesc ZZCorrect

Pressing Escape returns to normal mode, then typing ZZ (two uppercase Z keystrokes) is a built-in vi shortcut that writes the buffer to disk and quits, equivalent to :wq.

Bctrl :w!

Ctrl+: is not a valid vi key sequence - command-line mode in vi is entered by pressing the colon key alone from normal mode, not via Ctrl.

Cesc zz

Lowercase zz is a vi normal-mode command that redraws the screen with the current line centered - it does not save or exit.

Desc :wq!Correct

Pressing Escape ensures normal mode, then :wq! enters command-line mode, writes the file with w, quits with q, and the ! forces the write even on read-only files or when no changes are detected.

Ectrl XX

Ctrl+XX is an Emacs keybinding with no equivalent meaning in vi, and pressing it in vi normal mode has no save-and-quit effect.

Concept tested: vi editor save and exit command sequences

Source: https://man7.org/linux/man-pages/man1/vi.1p.html

Topics

#vi editor#save and exit#ZZ#:wq

Community Discussion

No community discussion yet for this question.

Full LX0-103 Practice