I have a .bin file which has a size of 8192. If I open the file in Vi, then use :wq without making any changes, the file size becomes 8193. What's happening? It's a HEX file if that makes any difference.


This is what was added to the file by Vi:

0a                                    |.|

1 Answer 1


Most likely, Vi adds a trailing linefeed. There used to be whole flame wars whether editors should add a trailing linefeed for the content.

It is a convention, that differs between Windows (there you would usually talk about line separators) while on Unix like operating systems one usually speaks about line terminators. (The most convincing argument for using terminators for me was using something like cat file1 file2 so that the when the lines from the second file are output, they start at a new line.)

However, to disable this behaviour, you can start Vim in binary mode (which as the name suggest should be used for editing binary files and resets quite a couple of options that might unintentionally change your file, which you can read at the documentation: :h 'binary'). For normal files however, you can nowadays also set the 'endofline' or 'fixendofline' option, which simply disables writing the final line termination character.

(Note: the 'endofline' option only works when the 'binary' option is set, which is usually suboptimal, so if you really need this, I would recommend unsetting the 'fixeol' option).


Your Answer

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

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