Basic info
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.
Experiment 1
You can do this small experiment to check this behaviour. In the terminal execute:
$ vim test_test
Enter the character 1
and save the file :wq.
You have only one character in the file, right? Actually no :) You now have in your file 1
and LF
characters. Let's check it, with hexdump utility:
$ hexdump test_test
0000000 31 0a
0000002
31
is ASCII code for character 1
, and 0a
is ASCII code for non-printing LF
character which for the UNIX as you may already know code for end of line.
Experiment 2
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
Then again let's look inside it with hexdump:
$ hexdump test_without_eol
000000 31
0000001
So there are no any eol
characters here. Let's open this file in vim:
$ vim test_without_eol
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:
:set listchars=eol:$
it will show all eol
characters as $
sign.