According to this page it is related to the smcup & rmcup capability: http://chenyufei.info/blog/2011-12-15/prevent-vim-less-clear...
Re:Practical Tmux
by keeperofdakeys on Friday May 16, 2014 @10:38PM
(#7759063)
This is a weird feature called a "secondary screen", which means that the terminal secretly has a second buffer to draw ncurses programs on. The OP probably had this disabled in screen, so it didn't work in their terminal.
By [1] To turn it on add 'altscreen on' to
~/.screenrc
Re:Practical Tmux
by SoftwareMaven on Friday May 16, 2014 @07:47PM
(#7758587)
And I just tested it, too, and my terminal contents were restored. As they were with nano and emacs.
> doesn't this depend on whether the program calls curses endwin() function ? why does tmux/screen need to know about this ?
I just tested out of curiosity. Running vim and exiting in tmux reverts to the previous screen contents, like in raw urxvt; in screen, the previous screen contents are lost. I do not know why.