Vim show newline at the end of file
'endofline'
is on by default so you don't need it in your ~/.vimrc
.
EOL or "newline" doesn't mean "there's an empty line after here", it means "this marks the end of the line, any further characters are to be displayed on another line". "newline" != "new line".
The last line of your file is #21 and it ends with a "newline" character. Since there's no actual line after that "newline" character, no line #22, showing a line #22 is not only wrong but misleading.
TextMate's behavior is wrong.
Vim's behavior is correct.
If you want Vim to show a line #22, you'll need to explicitly add that line but it sounds rather silly to me.

Comments
-
Keith Smiley 12 months
Using the
set eol
option Vim automatically adds a newline to the end of the file when it's saved. I have this option on but I would like to be able to see this newline in Vim, so I know that it's actually there.For example with a file in Vim:
And the same file in TextMate:
This always tricks me and I end up adding a second new line and end up realizing later. This exact same question was posted here but the answer that was accepted didn't answer this portion of the question.
Using
set list
:I can see there is a
$
character denoting a new line after the last line but this also litters the rest of the file with these. I know I could set up a toggle for this but I'd really prefer the TextMate like behavior. -
Keith Smiley about 10 yearsOne thing to note is that this behavior is by every native OS X text editor, not just TextMate
-
romainl about 10 yearsCould you post your file? I don't see that pesky line here on the two latest version of textmate I just downloaded.
-
Keith Smiley about 10 yearsgo to your last line, press enter, save it, open in vim, that line you just created won't be there.
-
neverhoodboy about 8 yearsThough correct, the problem with this behavior is that, a human reader cannot easily finds out whether there is an eol for the last line of the file, except for that
[noeol]
sign in the bottom status line (which is way too hard to notice). Things get worse with the fact that almost all GUI text editors in Win/Mac adopt the other way: treat newline as line separator rather than line terminator, so that the visual appearance around the end of file directly tells user the existence (or non-existence) of an eol. -
neverhoodboy about 8 yearsAdd the
[noeol]
sign will only be there right after you open the file. It will disappear once you perform any non-trivial operation. -
Iulian Onofrei over 6 yearsTextMate's behavior isn't wrong at all! Every editor in the world shows that empty line which vim doesn't display!
-
Iulian Onofrei over 6 years@KeithSmiley, How did you solve the problem? Why did you accepted this as a solution?
-
romainl over 6 years@IulianOnofrei, there's no line to display.
-
Iulian Onofrei over 6 years@romainl,
vim test
>i
>enter
>esc
>:wq
>vim test
> line 2 is gone! I manually pressed the enter key with my fingers and typed it, so I expect it to remain there, as I typed it on purpose, yet it disappears! Vim is wrong. -
romainl over 6 years@IulianOnofrei, no, line 2 is not gone.
-
Iulian Onofrei over 6 years@romainl, Are you for real? Before
:wq
, the sidebar shows1 2
, after it, the sidebar shows1
. Are you trying to tell me that these are equal? -
Iulian Onofrei over 6 yearsLet us continue this discussion in chat.
-
4LegsDrivenCat almost 6 yearsLet aside what is wrong and what is correct. Is there a way to configure vim to show that final line? I mean to configure it to work "incorrectly" as most of Win/Mac editors do?
-
romainl almost 6 years@4LegsDrivenCat, again, there's no line to show.
-
4LegsDrivenCat almost 6 yearsI said "Let aside what is wrong and what is correct".
-
romainl almost 6 yearsAnd I said "there's no line to show". Vim can't be configured to show a line that doesn't exist.
-
4LegsDrivenCat over 5 yearsPlease reread the comment of neverhoodboy above. It explains a lot. More info on wikipedia.
-
romainl over 5 yearsI already read it two years ago and I have written another longer answer to a similar question two years before. There is no line to display and no way to force Vim to display a line that's not here, no matter if you are comfortable with that behavior or not.
-
romainl about 5 years
Ga
is "jump to last line and append after the cursor" so there's no reason whatsoever to use that command to "jump to last line and add a new line". You would useGo
for that. -
johncip over 2 yearsNot only is not "wrong" to treat a newline as a separator, there is no newline character. There's a linefeed character, which tells a line printer to move the paper forward, and a carriage return character. How those get repurposed in ASCII files is a matter of convention, and varies with operating system and software. (Which also means that whether the newline character implies the existence of a blank line after it is, again, down to what you're using.) Vim's default happens to be most convenient for writing version-controlled code.