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:
cd
mv .vimrc .vimrc-safe
mv .vim .vim-safe
Then it's binary chop time, which should be fun. :-)
Hope this helps.
$TERM
variable is wrong. stackoverflow.com/questions/15892092/weird-tmux-vim-through-ssh/…screen-256color
andxterm-256color
.screen
orscreen-256color
? What does your TERM variable default to?screen
; that also fails :(