If the system crashes, the contents of your buffer are at risk. Often, though, you can recover most of your work by restarting vi with the command form:
vi -r filename |
where filename is the file you were editing at the time of the crash. The system will usually send you mail after the system is restarted, telling you there is a recover file.