vi swap file is empty

3

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?

arwright3

Posted 2013-04-04T22:49:45.667

Reputation: 31

Answers

1

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.

Heptite

Posted 2013-04-04T22:49:45.667

Reputation: 16 267

1

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: https://stackoverflow.com/questions/63104/smarter-vim-recovery

Bradd Szonye

Posted 2013-04-04T22:49:45.667

Reputation: 811