vim has a mode "eol" (for end-of-line) to tell what to if the last line in the file lacks a newline character. You can see all of the mode settings in vim (or any program like vi) by
POSIX vi does not have a feature for this: files are either zero-length, or have a trailing newline. That's because POSIX vi only deals with text files, which by definition are lines that end with newlines. In a quick check, nvi and elvis do not have modes for this. In my comment, I had forgotten a detail of vim: unlike vile, a ":set list" does not readily show the missing newline. Here's what I see in vim:
while in vile:
For either editor, you can read the file in, change the mode, e.g.,
and write the file out, to get a newline on the updated file. Rather than showing it directly, you can modify the status line of vim to show this information. By default, it does not appear to do this, but some packagers have customized this, e.g.,
"foo" [noeol] 2L, 9C 1,1 All
One of the comments suggests using the "?" modifier of the
set command, e.g.,
which might show something like this:
noendofline 2,1 All
but in insert-mode, that is replaced by
-- INSERT -- 2,1 All
so the status line seems the right place to maintain this information.
The features have been there a while:
eol feature first appeared in vim 2.4 (July 1994), according to a comment in its source code.
newline mode appeared in July 1993.
(nvi, elvis, vim and vile all handle binary files in addition to the POSIX vi's text files).