How to Exit the Vi or Vim Editor
Esckey a few times. This will ensure vi is out of Insert mode and in Command mode.
Enter. This tells vi to quit without saving any changes.
(If you do want to save your changes, type
Source: Dave McKay