To add an empty line at the end of the file
Go<Esc>
or in a script
normal Go^[
where ^[ is "hit Ctrl-V" "hit Esc" (replace Ctrl-V by Ctrl-Q if you use
Ctrl-V to paste the clipboard)
Additionally, in a script, you can use
:$put =''
to add empty lines at the bottom of the file
To remove an empty line at the end of the file
:if getline("$") =~ '^\s*$' | $d | endif
("if the last line is all whitespace, remove it")
or alternatively:
:/^\s*\%$/d
To remove any number of empty lines at the end:
:while getline("$") =~ '^\s*$' | $d | endwhile
or alternatively
:%s/\_s*\%$
will remove all the trailing whitespace in the file. If you want
to only remove truely blank lines (no whitespace in them) you can use
:%s/\n*\%$/
So many ways to do the same thing. Strange that I like that
ability in Vim, but abhor perl for the same reason. :) (maybe
because I write vim one-liners as a use-once-and-dispose-of-it,
and would grow to hate such opaque hacks if I had to go back and
read them later, like one would have to do with perl code)
-tim