1

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?

fkengun
  • 13
  • 3

1 Answers1

1

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.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
  • Thank you for your help. MobaXterm does not have infocmp. Probably I will give up on Windows client. Now I only want to get it done on Ubuntu client. infocmp returns the modern xterm database for both my Ubuntu client and Ubuntu server. I change them to the original ones but the vim screen becomes a whole black screen when I hit Ctrl+Z and the bash history disappears. Do you have more idea about it? – fkengun Jun 09 '15 at 02:43