Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This thing is driving me crazy. I have already searched the internet and SE and found a lot of related questions but none solve my problem.

I'm using Zsh inside tmux. Until a couple of days ago everything was working fine, but now when I exit vim, the contents of the buffer remain on the screen. I don't want that. I get that behaviour on less by passing -X option. The problem is that vim terminal configurations look fine:

:set t_ti?: t_ti=^[[?1049h :set t_te?: t_te=^[[?1049l

tmux's alternate-screen option is on.

I'm not sure where to look at now.

FWIW, here are my dotfiles:

share|improve this question
Your $TERM variable is wrong.… – FDinoff Jan 8 '14 at 18:36
Sorry, no success; same behaviour with both screen-256color and xterm-256color. – Fuad Saud Jan 8 '14 at 18:45
The only two valid options are screen or screen-256color? What does your TERM variable default to? – FDinoff Jan 8 '14 at 18:47
screen; that also fails :( – Fuad Saud Jan 8 '14 at 18:56

First things first, those t_ti and t_te settings look good.

But to check the blindingly obvious (sorry)...

When you say ^[, this must be a single control character (Escape), not two characters (^ and [). I'm not sure how to check this specifically from within vim, but on my vim with :set t_ti? it shows the ^[ in a different colour, which sort of suggests it's one control character.

Also, you didn't mention what terminal emulator and platform you are running. It could have a bearing and you should put it in your question, along with versions of vim and tmux. However, if you are saying that you can already demonstrate both types of behaviour (desired and undesired) in the same problem terminal using the less command (without and with -X, respectively), then this would suggest that your terminal emulator and tmux settings are correct, and my suspicion goes towards vim.

Confirm this as follows (remember that ^[ must be entered as a control character, e.g. Ctrl-v followed by Escape):

less /etc/hosts         # should use alternate screen (desired)

less -X /etc/hosts     # should leave it's output on screen (undesired)

echo -n "^[[?1049h"; less -X /etc/hosts; echo -n "^[[?1049l"
    # should use alternate screen (desired)

If that last command gives the desired behaviour with less. Try the same approach with vim:

echo -n "^[[?1049h"; vim /etc/hosts; echo -n "^[[?1049l"
    # should use alternate screen (desired)

After you quit vim, the screen should be restored to it's previous contents (your desired behaviour). If so, then you could use this to put together a very cludgey workaround with an alias or a wrapper script. But if you reach this stage in your diagnosis, it's almost certainly a problem with vim or part of it's configuration not sending the t_te sequence as it exits, and I'd start by moving my .vimrc and .vim out of the way and testing with a clean config:

mv .vimrc .vimrc-safe
mv .vim .vim-safe

Then it's binary chop time, which should be fun. :-) Hope this helps.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .