I'm using mosh to access my remote Ubuntu machine. The client I'm using on Windows is MobaXterm which has a mosh plug-in. The one I use on Ubuntu is just the mosh client I get from apt-get. The problem is that I usually open a vim in bash to edit my code and go back to bash using Ctrl+Z. And I bring back vim using fg. BUT, when I hit Ctrl+Z, the content of my code is still on my terminal window with the bash comes below it. The SSH works perfectly. The code disappears and only something like this shows up.
[1]+ Stopped vim .bashrc
I guess this is related with my terminal setting. I use the default setting of Ubuntu. $TERM returns xterm. The terminal I use in MobaXterm is xterm also. Can anyone tell me how can I get the same result as SSH connection?
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
TERMtells the termcap/terminfo/curses library which terminal description to use. Here is where the difference lies: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
smcupandrmcupterminfo 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
infocmpprogram. Using theinfocmpprogram, you can see what its terminal database has for those values, e.g.,or
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 havetic. You can modify your local terminal database byinfocmpto create a file containing the terminal descriptionticto 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:
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) orvte(preferred) used the old xtermsmcup/rmcup. Ubuntu 14.04 is old enough that gnome-terminal did not properly recognize the newer xtermsmcup, and did not switch to the alternate screen usingTERM=xterm. But it did work withTERM=vte(orTERM=gnome). You would have those descriptions if thencurses-termpackage is installed.