4

I occasionally open a file with vim and see something like this:

"<file name>" [Incomplete last line][dos format] 71 lines, 2912 characters

I understand all of that information except Incomplete last line. I realize this just means that there isn't a line termination character on the last line, and I know if I resave the file and reopen it, that message goes away, which implies that vim automatically adds the line termination character if it isn't already present. My question is: why does this matter, and why does vim bother to tell me about it?

1 Answer 1

6

The Unix convention is that a line is a sequence of zero or more characters ending with a newline character. A text file is a sequence of such lines. This is just a convention, but adhering to that convention allows text-processing tools to work together. It avoids problems of ambiguity in commands such as cat foo bar when the last character of foo is not a newline.

A sequence of characters that does not end with a newline is not a "line", in this sense. It is incomplete and some tools will not process it as the user might expect. Vim warns you about it because it is a potential problem and fixes it because Vim attempts to write proper files.

2
  • git also warns about it. Mar 3, 2017 at 18:59
  • Alright, that logic does actually make sense to me. I hadn't thought about it that way. Thanks!
    – pattivacek
    Mar 3, 2017 at 21:35

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.