1

I open a file with vim, vim creates a swap file. Though I have not done any single edit on my file, the swap file has significant size, sometimes bigger than the size of the original file.

For example, original file = 1.4K, swap = 12K. What's written inside the swap file that makes it bigger than the original file?

2 Answers 2

2

Swap files appear to contain some basic information about your computer (try opening the swap file in vim! I found the vim version, pc name, file path&name, utf encoding and some other "settings" stored) as well as a whole lot of "nothing". The "nothing" is actually a significant amount of padded null characters ^@ (which I presume is used as a placeholder for the swap file to include other relevant information).

As such, swap files aren't actually "big", they just have some base information making them a bit bigger than the original file. As your files get larger, the % difference between the original file and the swap file becomes less significant.

1

Vim stores the things you changed in a swap file. Using the original file you started from plus the swap file you can mostly recover your work.

For a detail of What is the purpose of swap files?, follow the link.

2
  • I know the purpose of the swap file. But it gets to that size right after I open the file. No changes at all were made. I realize that not only the changes are stored there but also some meta information, like pid of the editing process etc. But it wouldn't make the swap as big.
    – 7px
    Oct 29, 2018 at 22:55
  • Well, it seems that yes. It would be necessary to analyze the source code of the VIM to know exactly what information it saves or reserves space. Oct 29, 2018 at 23:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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