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 TERM
tells 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 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
infocmp
to create a file containing the terminal descriptiontic
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:
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.