Like so many people, you seem to mix up "new line" and "newline".
When editing a file where the last line doesn't end with a "newline" character, Vim will add that "newline" character on write unless the 'noeol' and 'binary' option are set. So, basically, you probably always have that "newline" character at the end of your files, whether you see it or not.
The "newline" character can be interpreted in two ways:
- as a "line terminator", the editor considers anything that comes after a "newline" character to be on another line;
- as a "line separator", the editor considers that the "newline" character must be between two lines.
In the first interpretation, that "newline" character at the end of the last line can't really be displayed in any useful way because it is the same as any other "newline" character at the end of any other line in the file. If you think about it, there's no real need to even display it.
In the second interpretation, that "newline" character at the end of the last line is not displayed either but, because the interpretation mandates the presence of another line after the "newline" character, the editor adds a "new line" at the end of the file.
Adding such a "new line" at the end of the file just as misleading as it is unnecessary and wrong.
The Vim way is simply to assume the "newline" character is there and thus to not add an unnecessary "new line" at the end of the file.
Gowill start me writing on a new line with a blank between it and the last thing; on save I'll get that blank back. Without a blank line displayed, that'sGo<kbd>return</kbd>to achieve the same. Not a massive deal, but it's how I like it even if you disapprove :) – OJFord Dec 24 '15 at 13:44\nthat every other editor I have installed will recognise. – OJFord Dec 24 '15 at 21:23BufWritePreevent… – romainl Dec 24 '15 at 21:52:set list. It's like learning to use a fork after years of using a spoon, and complaining that it's not round. Wishing Vim was Notepad is not a productive use of your time. – Amadan Dec 25 '15 at 01:21\n) file. I don't see that an empty line is any weirder of an interpretation of a\ncharacter than nothing. In fact I think it might be saner: any visible character is displayed differently, in effect, according to whether or not it follows a newline ch. Showing a trailing empty line would be more in keeping with 'line feed', too. I'm not sure I actually want this behaviour any more, but I think I still 'believe in it' in principle. – OJFord Apr 23 '21 at 20:20This is a personal opinion, and one I don't share.
What is super misleading is the current situation where Vim displays a file that ends with a
– Cristian Vasile Mocanu Jan 04 '24 at 20:44\nexactly the same as a file that doesn't end in\n. Displaying 2 files with different content the same way is misleading (fact) and wrong (personal opinion :D).\nvs. a file that doesn't. I'm using neovim BTW, if that makes any difference. – Cristian Vasile Mocanu Jan 04 '24 at 20:45I don't understand why this question is met with condescending remarks so often! I personally don't want Vim to be Notepad. I want Vim to display differently files that have different content (ending or not with
– Cristian Vasile Mocanu Jan 04 '24 at 22:13\n). Is it so crazy for me to want to see clearly when 2 files are different? Now it just so happens that Notepad (and almost every other text editor in existence) show this difference by showing an empty last line when the file ends with\n. It's a good solution to the above problem.:set list; otherwise you implicitly agree to the UNIX line definition, and (withset eol) for Vim to correct your badly constructed text file. – Amadan Jan 05 '24 at 01:42'list'doesn't work like that: it displays the configuredlcs-eolregardless of whether it's going to write out an<EOL>after the last line when writing the file. – Rich Jan 05 '24 at 10:27'fixendofline'option was added. – Rich Jan 05 '24 at 10:39\nor not, without being forced to see\ncharacters on every line. Notepad can do this, so it's far superior to VIM in this respect. Another way is how GitHub does it - to show aØat the end of the file, when the file is missing a\nthere. Either way works with me (or any other way). The current behavior of VIM (to show different files identically) is just not acceptable. – Cristian Vasile Mocanu Jan 07 '24 at 10:18