When in vi, typing
:will bring the user into command mode. As the : is typed, it will be displayed on the last line of the screen, and vi will wait for a command to be typed.
q is such a command. This will exit vi, if no changes have been made since the last write-to-file command.
:q! (with an exclamation mark) will exit, even if the buffer has not been written to the file.