MacOS – File contents remains in terminal after exiting Vim

bashmacosterminalvizsh

I'm using the stock terminal with zsh and vim. After I exit vim, the file contents remains in the terminal. Ideally, only the previous history would be in the terminal when I exit vim (such as the behavior I've seen with linux/bash).

How can I accomplish that?

Update

I'm running os x Yosemite 10.10.1

I tried glenn jackman's suggestion below, but still no dice.

Additional information:

echo $TERM produces ansi

I also tried in bash with the same results.

I also tried removing .vimrc completely with the same results.

Best Answer

I figured it out:

Similar to glenn jackman's solution, I added

if &term =~ "ansi"
    let &t_ti = "\<Esc>[?47h"
    let &t_te = "\<Esc>[?47l"
endif

to my .vimrc file (notice the ansi instead of xterm).

This fixed the issue.