System Management

A junior administrator opens /etc/hosts in vim, adds a new entry, and then realizes the edit was made in the wrong file. The administrator wants to leave vim immediately, discard every change made in this session, and keep the file exactly as it was on disk. While in command mode, which key sequence should the administrator enter?

Show the answer

Correct answerA. :q!

:q! quits vim and discards unsaved changes, leaving the file on disk untouched. :w! forces a write, so it would save the unwanted edit to the file rather than discard it, and it also does not exit the editor.