Skip to content

Using remote vim over Windows openssh inserts text into the file automatically #19577

Closed

Description

@Fyren

Windows Terminal version

1.23.12811.0

Windows build number

10.0.19045.0

Other Software

Remote: vim-9.1.1336
Local: OpenSSH_for_Windows_10.0p2 Win32-OpenSSH-GitHub, LibreSSL 4.2.0 (also happens with 9.5p1)
Local: Linux yomi 6.6.87.2-microsoft-standard-WSL2 #1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

Steps to reproduce

  1. ssh to remote system
  2. vim doesntexist

Expected Behavior

vim would open with an empty buffer.

Actual Behavior

vim opens and immediately inputs text into the file in more than 75% of cases. Sometimes, it does work as expected. For me, it almost always inserts c0c0 or /c0c0, but rarely seems to insert slightly different text.


Related seems to be issue #1637 which is marked as fixed in 2020 (with Terminal 1.4 or so?). I found that issue through #12164 which was eventually marked as a dupe of the former.

There's vim/vim#6365 marked as closed with the fix being in Terminal.

If I run the command from #1637 (comment) I get this (after pressing enter a few more times to get hd to output):

00000000 1b 5b 32 3b 32 52 1b 5b 33 3b 33 52 0a 0a 0a 0a |.[2;2R.[3;3R....|

This doesn't match the given expected output nor the given actual output from Terminal at the time.

Additionally, from vim/vim#6365 (comment), if I have vim output that additional logging info, I get this:

==== start log session Sun Nov 23 14:36:33 2025 ====
  0.025072600 : raw terminal output: "ESC[?1049hESC[22;0;0tESC[>4;2mESC[?1hESC=ESC[?2004hESC[?1004h"
  0.025164054 : raw terminal output: "ESC[1;30rESC[?12hESC[?12lESC[22;2t"
  0.025541736 : raw terminal output: "ESC[27mESC[23mESC[29mESC[mESC[HESC[2JESC[2;1H▽ESC[6n"
  0.025575884 : raw terminal output: "ESC[2;1H  ESC[3;1HESCPzzESC\ESC[0%mESC[6n"
  0.025629137 : raw terminal output: "ESC[>c"
  0.025661407 : raw terminal output: "ESC]10;?^GESC]11;?^G"
  0.026055930 : SafeState: Start triggering
  0.026663372 : setting timeout timer to 2 sec 0 nsec
  0.026957183 : looking for messages on channels
  0.026976768 : SafeState: back to waiting, triggering SafeStateAgain
  0.121551739 : raw key input: "ESC[3;3RESC[2;2RESC[3;3RESC[2;2Rc0/c0c0ESC\"
  0.121703787 : SafeState: reset: key typed
  0.122962544 : setting timeout timer to 2 sec 0 nsec
  0.123107819 : SafeState: Start triggering
  0.123143032 : looking for messages on channels
  0.123156800 : SafeState: back to waiting, triggering SafeStateAgain
  0.148485774 : raw key input: "c0/c0c0ESC\00/0000ESC\"
  0.148595563 : SafeState: reset: key typed
  0.149243984 : setting timeout timer to 2 sec 0 nsec
  0.149646816 : SafeState: Start triggering
  0.149685080 : looking for messages on channels
  0.149699609 : SafeState: back to waiting, triggering SafeStateAgain
  3.559813415 : raw key input: ":"
  3.559925446 : SafeState: reset: key typed
  3.560017843 : SafeState: Start triggering
  3.560047949 : looking for messages on channels
  3.560059937 : SafeState: back to waiting, triggering SafeStateAgain
  3.834924500 : raw key input: "q"

The ESCs are literal 0x1bs. You can see in the 12th or 18th lines the strings c0c0. (I've attached the actual file, just in case.) logfile.txt

My TERM is set to xterm-256color. Two workarounds mentioned in the vim issue, set t_u7= and set ambw=double do not appear to help. Changing my TERM to linux, for testing, does seem to help.

Activity

  1. added
    Issue-BugIt either shouldn't be doing this or needs an investigation.
    Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
    on Nov 23, 2025
  2. added theissue type on Nov 23, 2025
  3. lhecker commented on Nov 24, 2025

    @lhecker
    Member

    See here for a lengthy discussion with lots of links: #18004

    Recent versions of Windows Terminal had a few fixes. There's two remaining problems to my knowledge:

    • Old versions of "ConPTY" (= aka "conhost.exe = a library for providing PTYs on Windows & VT handling) are hella buggy and we have no way of updating them on old Windows 10 versions. If you don't care about the integrity of your OS, you can take any recent OpenConsole.exe you have on your system and simply copy it over C:\Windows\System32\conhost.exe. This may break OS updates until you use DISM to restore your OS integrity. But this will fix a lot of bugs on your Windows 10 setup.
    • OpenSSH, particularly old OpenSSH, is also buggy - I recommend compiling it yourself with this fix included which can cause the exact issue you're seeing: Fix duplicate output on console resize event PowerShell/openssh-portable#806
  4. o-sdn-o commented on Nov 24, 2025

    @o-sdn-o

    you can take any recent OpenConsole.exe you have on your system and simply copy it over C:\Windows\System32\conhost.exe.

    Please note that on Windows 10, replacing the supplied conhost.exe with OpenConsole.exe will introduce other issues, for example, sftp access sftp user@win10 will completely stop working.

  5. DHowett commented on Nov 24, 2025

    @DHowett
    Member

    replacing the supplied conhost.exe with OpenConsole.exe will introduce other issues

    Issues like this are important to us, because that's pretty much what happens when we upgrade conhost in the Windows source code as well. Do you know if it repros there?

  6. o-sdn-o commented on Nov 24, 2025

    @o-sdn-o

    When replacing the default conhost.exe with OpenConsole.exe:

    • On Windows 10, the sftp user@127.0.0.1 session hangs.
    • On Windows 11, the sftp user@127.0.0.1 session closes immediately:
      PS C:\Users\sdn> sftp sdn@127.0.0.1
      sdn@127.0.0.1's password:
      Connection closed
      PS C:\Users\sdn>
      

    With default conhost.exe everything works as it should:

    PS C:\Users\sdn> sftp sdn@127.0.0.1
    sdn@127.0.0.1's password:
    Connected to 127.0.0.1.
    sftp> ls
    AppData
    Application Data
    Contacts
    Cookies
    Desktop
    Documents
    ...
    
  7. o-sdn-o commented on Nov 24, 2025

    @o-sdn-o
  8. DHowett commented on Nov 24, 2025

    @DHowett
    Member

    Because of this risk, generic shells are unlikely to adopt win32-input-mode in its current form.

    Sorry. On Windows 11 with conhost. You covered that though :)

  9. DHowett commented on Dec 3, 2025

    @DHowett
    Member

    Yep, I'm gonna call this a /duplicate of PowerShell/openssh-portable#806

    Thanks!

  10. microsoft-github-policy-service commented on Dec 3, 2025

    @microsoft-github-policy-service
    Contributor

    Hi! We've identified this issue as a duplicate of one that exists on somebody else's Issue Tracker. Please make sure you subscribe to the referenced external issue for future updates. Thanks for your report!

  11. added
    Resolution-ExternalFor issues that are outside this codebase
    and removed
    Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
    on Dec 3, 2025
  12. Fyren commented on Apr 8, 2026

    @Fyren
    Author

    Sorry for the late reply, but I finally got around to compiling openssh myself. The indicated PR (PowerShell/openssh-portable#806) was merged into latestw_all (PowerShell/openssh-portable@2586de1) in December and I built the current head of that branch for testing.

    I ran through the same things mentioned in the original report and the behavior is the same. In most cases running vim ends up automatically switching to insert mode and inserting text. Changing TERM to linux still appears to stop the problem from happening.

    The example command piped to hd is still weird but is maybe working as expected, but I don't understand what the echo'd stuff is supposed to do to the terminal. My output is different because I have to hit enter a few times to get hd to produce output, which are the extra 0as, I guess? If I have vim log its output, it's the same as the original.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIt either shouldn't be doing this or needs an investigation.Resolution-ExternalFor issues that are outside this codebase

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions