2

When I connect to a remote macOS Sonoma from a Linux RHEL 8 with ssh -J user@portal user@mac and, once connected, I run vim somefile, I get some extraneous characters at the top-left of the "page" and also at the shell prompt after exiting Vim:

ESC[>4;m

note: Thanks to @LorinczyZsigmond tip of using script I managed to capture those bytes

It's not the first time I'm experiencing this problem, with differents local/remote OS combinations (Solaris/FreeBSD/AIX/Linux/macOS), but previously I only had to install the terminfo packages on the remote NIXes to fix it.

On macOS Sonoma though, the terminfo for the xterm-256color used by RHEL 8 is already in /usr/share/terminfo/78/xterm-256color, and changing TERM to xterm doesn't help.

Any thoughts on what to do to fix the problem?

3
  • 1
    Utility script (if available on that platform), can help to determine the problematic ESC-sequence. Commented Dec 9, 2024 at 12:47
  • @LorinczyZsigmond Thanks to your tip I could determine that the problematic control sequence is CSI > Ps ; Ps m (AKA CSI > Pm m). As it's an Xterm control sequence, my terminal should understand it, but it doesn't, so the TERM=xterm-256color that comes out-of-the-box is simply wrong... Commented Dec 9, 2024 at 21:48
  • So far I've only found CSI > ... c (Device attributes),,and CSI > ... g (reset tabulator poisitions). Commented Dec 10, 2024 at 5:15

2 Answers 2

3
UPDATE

It turns out that GNOME Terminal (default graphical terminal of RHEL 8) sets the TERM environment variable to xterm-256color even though it doesn't implement the whole set of Control Sequences of Xterm...

According to this document, the Control Sequence ESC[>4;m corresponds to CSI > Pm m:

CSI > Ps n
          Disable key modifier options, xterm. These modifiers may be
          enabled via the CSI > Pm m sequence. This control sequence
          corresponds to a resource value of "-1", which cannot be set
          with the other sequence.

          The parameter identifies the resource to be disabled:

            Ps = 0  ⇒  modifyKeyboard.
            Ps = 1  ⇒  modifyCursorKeys.
            Ps = 2  ⇒  modifyFunctionKeys.
            Ps = 4  ⇒  modifyOtherKeys.

          If the parameter is omitted, modifyFunctionKeys is disabled.
          When modifyFunctionKeys is disabled, xterm uses the modifier
          keys to make an extended sequence of function keys rather than
          adding a parameter to each function key to denote the
          modifiers.

The solution is simply to set TERM to the correct value for GNOME Terminal, i.e. gnome-256color. But, setting TERM in the shell profile (or rc) file isn't so good of an idea when you connect to your machine remotely from different OSs, so it's safer to edit the preferences of GNOME Terminal and add a Run a custom command instead of my shell:

/usr/bin/env TERM=gnome-256color /bin/bash

OLD ANSWER

Not an answer but a workaround

By trying different TERM values I found one that makes Vim work: screen

So a workaround could be to add the following code to the shell profile file of the remote machine:

[ "$TERM" = xterm-256color ] && TERM=screen

While I can make do with it, I would prefer to understand where the problem lies exactly.

4
  • 1
    Why not just TERM=screen? Why only do it if it is set to one specific value? And are you using screen or tmux here? I get the same issue when I open an existing screen (byobu, actually, but using screen as a backend) session. Are you getting it without screen being involved? Commented Dec 7, 2024 at 13:11
  • @terdon Well, I'm also using that computer directly (not through SSH). Next week I'll check what TERM is set when I open a Terminal on it; I'm pretty sure it isn't screen. Commented Dec 7, 2024 at 13:18
  • @terdon No I'm not using any terminal multiplexer here Commented Dec 7, 2024 at 13:18
  • 1
    @terdon The default TERM on macOS Sonoma is also xterm-256color, so it is overwritten to screen when I open a Terminal... A local Vim doesn't doesn't display junk characters but the colors are a little awful... Commented Dec 9, 2024 at 12:18
1

I get some extraneous characters at the top-left of the "page" and also at the shell prompt after exiting Vim:

I don't know if this is a solution to your specific experience, but I have found over the years when using RHEL 7, and 8, that it does not by default have all fonts installed, and after yum install'ing them a lot of such extraneous characters then either disappear or display as readable. And I always noticed this in vi

So whenever possible I always try to have a yum install xorg-x11-fonts* done

which then results in the following being installed, as I currently see it in RHEL-8.10

xorg-x11-fonts-75dpi-7.5-19.el8.noarch
xorg-x11-fonts-ethiopic-7.5-19.el8.noarch
xorg-x11-fonts-ISO8859-15-75dpi-7.5-19.el8.noarch
xorg-x11-fonts-ISO8859-14-100dpi-7.5-19.el8.noarch
xorg-x11-fonts-misc-7.5-19.el8.noarch
xorg-x11-fonts-ISO8859-14-75dpi-7.5-19.el8.noarch
xorg-x11-fonts-ISO8859-9-100dpi-7.5-19.el8.noarch
xorg-x11-fonts-ISO8859-1-100dpi-7.5-19.el8.noarch
xorg-x11-fonts-ISO8859-9-75dpi-7.5-19.el8.noarch
xorg-x11-fonts-ISO8859-1-75dpi-7.5-19.el8.noarch
xorg-x11-fonts-ISO8859-2-100dpi-7.5-19.el8.noarch
xorg-x11-fonts-100dpi-7.5-19.el8.noarch
xorg-x11-fonts-ISO8859-2-75dpi-7.5-19.el8.noarch
xorg-x11-fonts-ISO8859-15-100dpi-7.5-19.el8.noarch
xorg-x11-fonts-Type1-7.5-19.el8.noarch
xorg-x11-fonts-cyrillic-7.5-19.el8.noarch
1
  • Thanks @ron, that's also something I often do for having smoother fonts and displaying characters of other alphabets +1. Though I don't think it modifies Vim's behavior regarding the control sequences it sends to the terminal. Commented Dec 10, 2024 at 19:13

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.