Vim doesn't show latest newline in the buffer but actually vim always place EOL at the end of the file when you write it, because it standard for text files in Unix systems. You can find more information about this here. In short you don't have to worry about the absence a new lines at the end of the file in vim.
You can do this small experiment to check this behaviour. In the terminal execute:
enter for example only character
1 and save file :w.
You have only one character in the file, right? Actually no :) You now have in your file
LF characters. Let's check it, with hexdump utility:
0000000 31 0a
31 is ASCII code for character
0a is ASCII code for non-printing
LF character which for the UNIX as you may already know code for end of line.
But what if we will open file which don't have
eol symbol at the end of the file. Let's check it too. Let's create file without eol at the end, for example like this:
$echo -n "1" > test_without_eol
and then again let's look inside it with hexdump
output will be:
So there are no any
eol characters here. Let's open this file in vim:
At the bottom of editor you'll see:
"test_without_eol" [noeol] 1L, 1C
And if you'll save this file
eol character will be putted automatically.
What we can do about this?
If you really need to see end of the file. Try to use this command:
it will show all
eol characters as