One way to quit vi is through :wq, which will save the current buffer before quitting. You can also quit without saving with :q or (more commonly) :q!. The latter is used when you've modified the file but do not wish to save any changes to it.
On occasion, your machine might crash or vi might crash. However, both elvis and vim will take steps to minimize the damage to any open buffers. Both editors save the open buffers to a temporary file on occasion. This file is usually named similarly to the open file, but with a dot at the beginning. This makes the file hidden.
This temporary file gets removed once the editor quits under normal conditions. This means that the temporary copy will still be around if something crashes. When you go back to edit the file again, you will be prompted for what action to take. In most cases, a large amount of your unsaved work can be recovered. elvis will also send you a mail (from Graceland, oddly enough :) telling you that a backup copy exists.