# It does not produce empty lines.

It moves the cursor to the bottom left-hand corner of the screen, which is where it happens to be sent when you issue a command like `:q` or `ZZ`, usually because you have just entered an `ex` command or because it has updated the status line.

And it only does so because your terminal description in `terminfo` either does not include capabilities for entering and exiting _cursor addressing mode_ at all, or includes enter/exit cursor addressing mode capabilities that do not employ the DECSM/DECRM Private Mode sequences that command saving/restoring the cursor position _in addition to_ commanding switching to and from the alternate screen buffer. (DEC Private Modes 1047 and 47 only command switching to and from the alternate screen buffer.  It is DEC Private Mode 1049 that commands saving/restoring the cursor position as well.)

Normally, immediately upon exiting `vim`, like other programs that present a _full screen textual user interface_, exits cursor addressing mode.  Because that restores the cursor position from when it _entered_ cursor addressing mode, back when `vim` and such programs started up their full-screen textual user interfaces in the first place, the cursor is thereby moved from the bottom left-hand corner to wherever it was when the program started.

That lack of `terminfo` capabilities, in turn, is most probably because you have not used the correct description for your terminal/terminal emulator.  The most common error is to abuse `xterm`, exactly as you are doing it transpires.  Unless your terminal emulator _really is the XTerm program_, that terminal type is wrong for your terminal.  Use [`iTerm.App`](http://invisible-island.net/ncurses/terminfo.ti.html#tic-i_Term_App), [`vte-256color`](http://invisible-island.net/ncurses/terminfo.ti.html#tic-vte-256color), [`tmux-256color`](http://invisible-island.net/ncurses/terminfo.ti.html#tic-tmux-256color), [`putty-256color`](http://invisible-island.net/ncurses/terminfo.ti.html#tic-putty-256color), [`nsterm`](http://invisible-island.net/ncurses/terminfo.ti.html#tic-nsterm), and so forth, as appropriate.  

Note that the terminal emulators that are built into the Linux, OpenBSD, NetBSD, and FreeBSD kernels themselves, denoted by the [`linux-16color`](http://invisible-island.net/ncurses/terminfo.ti.html#tic-linux-16color), [`pccon`](http://invisible-island.net/ncurses/terminfo.ti.html#tic-pccon), and  [`pcvt25`](http://invisible-island.net/ncurses/terminfo.ti.html#tic-pcvt25) terminal types, do not have alternative screen buffer mechanisms and so do not have `terminfo` capabilities for entering/exiting cursor addressing mode, and this is the _only_ behaviour that you will get from any full-screen program on such terminals.

# Further reading
* https://unix.stackexchange.com/a/243320/5132
* https://superuser.com/a/715563/38062
* https://unix.stackexchange.com/a/336635/5132
* https://unix.stackexchange.com/a/419092/5132
* Thomas E. Dickey (2018). "[What versions are available?](http://invisible-island.net/xterm/xterm.faq.html#other_versions-id)". _XTerm FAQ_. invisible-island.net.
* https://unix.stackexchange.com/questions/288962/