The behavior where the screen is cleared and only a short message remains sounds like a program that is switching between xterm's normal and alternative screens. MobaXterm uses PuTTY, which does implement this feature from xterm.
The setting for TERM
tells the termcap/terminfo/curses library which terminal description to use. Here is where the difference lies:
- In the case of the mosh program, that library is on your local machine.
- When using ssh, that library is on the remote machine.
It is more complicated than that: vim is actually using the terminal database on the machine where you are running it, but mosh is having the final say over what escape sequences are sent to the terminal. So it sounds as if mosh is seeing a local terminal description where the smcup
and rmcup
terminfo capabilities do not tell the "xterm" to switch to/from the alternate screen.
I don't have MobaXterm at hand to check, but you can check this. mosh is a curses/ncurses program. So it is reasonable to suppose that MobaXterm also has the infocmp
program.
Using the infocmp
program, you can see what its terminal database has for those values, e.g.,
smcup=\E[?1049h,
rmcup=\E[?1049l,
or
smcup=\E[?47h,
rmcup=\E[2J\E[?47l,
The latter are the original xterm sequences (early 1990s), the former are modern xterm (late 1990s). Interestingly enough, some "xterm" emulators do not implement the newer ones. Some details are in the xterm FAQ Why doesn't the screen clear when running vi?
If you have infocmp
, then you likely would have tic
. You can modify your local terminal database by
- use
infocmp
to create a file containing the terminal description
- edit the file (adding lines for those two, or using the older values if the newer ones happen to not work)
- use
tic
to recompile the terminal description
(If MobaXterm provides mosh without the curses utilities, there is not much that you can do except file a bug report with MobaXterm).
The above was written June 8. I took a look at MobaXterm last night and have a few comments:
- MobaXterm is self-contained (an application using busybox), so I normally would not pay much attention to it.
- It has a moderately old terminal description for xterm (I could pinpoint it, but offhand, probably 5-8 years old).
- The alternate screen switching is much older, and as you indicated there was not much to be done, I did not investigate further.
- If it were necessary, it is likely that you could copy a compiled terminfo entry from Linux (but that would be a nuisance).
For Ubuntu, I took a quick look at my 14.04 machine with vim running in gnome-terminal and xterm. As a coincidence I was reviewing the former's terminal description recently and noticed that the entry which I wrote for gnome
(obsolete) or vte
(preferred) used the old xterm smcup
/ rmcup
. Ubuntu 14.04 is old enough that gnome-terminal did not properly recognize the newer xterm smcup
, and did not switch to the alternate screen using TERM=xterm
. But it did work with TERM=vte
(or TERM=gnome
). You would have those descriptions if the ncurses-term
package is installed.