Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

If vim crashes and leaves me with a .swp file that is empty (i.e., file size = 0), does that mean I didn't make any changes to the file during the session in which my computer crashed?

If so, then is there a way to change the settings so that vim will prompt me about “swap” files only if they are non-empty?

share|improve this question

2 Answers 2

It can mean there were no unwritten changes, or it could mean Vim did not have a chance to save to the swap file; Vim doesn't write the swap file constantly. See ":help 'updatetime'" (with the single quotes as part of the command).

In light of this, having Vim prompt you even with an empty swapfile can be a useful warning that something went wrong, and to take a close look at your file for lost data.

share|improve this answer

Vim swap files begin with the magic string b0VIM followed by a space and the Vim version number. An empty swap file is not normal and may indicate a more serious problem.

Note that the ATTENTION message exists partly to warn you when another Vim process is editing the same file, so you may want to keep it even for cases where you know there are no pending changes. The warning tells you whether the file is modified and whether the previous process is still running: If neither, it should be safe to delete the swap file, otherwise you should proceed with caution.

You can disable the ATTENTION message with set shortmess+=A, but Vim does not expose enough information about recovery in the API to disable the message automatically in low-risk situations. If you're very careful about workflow, you could disable the message and then deal with recovery manually as necessary. If you take this approach, you may want to streamline swap file processing like this: http://stackoverflow.com/questions/63104/smarter-vim-recovery

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.