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.
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)- A90% (26)
- B7% (2)
- E3% (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.
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.
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.
Lowercase zz is a vi normal-mode command that redraws the screen with the current line centered - it does not save or exit.
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.
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
Community Discussion
No community discussion yet for this question.