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

Closed
opened 2026-01-31 08:53:48 +00:00 by claunia · 8 comments
Owner

Originally created by @Fyren on GitHub (Nov 23, 2025).

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 https://github.com/vim/vim/issues/6365 marked as closed with the fix being in Terminal.

If I run the command from https://github.com/microsoft/terminal/issues/1637#issuecomment-687704325 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 https://github.com/vim/vim/issues/6365#issuecomment-687604270, 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.

Originally created by @Fyren on GitHub (Nov 23, 2025). ### 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 https://github.com/vim/vim/issues/6365 marked as closed with the fix being in Terminal. If I run the command from https://github.com/microsoft/terminal/issues/1637#issuecomment-687704325 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 https://github.com/vim/vim/issues/6365#issuecomment-687604270, 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 `ESC`s are literal `0x1b`s. You can see in the 12th or 18th lines the strings `c0c0`. (I've attached the actual file, just in case.) [logfile.txt](https://github.com/user-attachments/files/23696524/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.
claunia added the Issue-BugResolution-External labels 2026-01-31 08:53:48 +00:00
Author
Owner

@lhecker commented on GitHub (Nov 24, 2025):

See here for a lengthy discussion with lots of links: https://github.com/microsoft/terminal/issues/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: https://github.com/PowerShell/openssh-portable/pull/806
@lhecker commented on GitHub (Nov 24, 2025): See here for a lengthy discussion with lots of links: https://github.com/microsoft/terminal/issues/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: https://github.com/PowerShell/openssh-portable/pull/806
Author
Owner

@o-sdn-o commented on GitHub (Nov 24, 2025):

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.

@o-sdn-o commented on GitHub (Nov 24, 2025): > 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.
Author
Owner

@DHowett commented on GitHub (Nov 24, 2025):

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?

@DHowett commented on GitHub (Nov 24, 2025): > 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?
Author
Owner

@o-sdn-o commented on GitHub (Nov 24, 2025):

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
...
@o-sdn-o commented on GitHub (Nov 24, 2025): 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 ... ```
Author
Owner

@o-sdn-o commented on GitHub (Nov 24, 2025):

Do you know if it repros there?

To be honest, I don't understand what "there" means: where "there" refers to the Windows source code or internal test environments or Windows instance.

@o-sdn-o commented on GitHub (Nov 24, 2025): > Do you know if it repros there? To be honest, I don't understand what "there" means: where "there" refers to the Windows source code or internal test environments or Windows instance.
Author
Owner

@DHowett commented on GitHub (Nov 24, 2025):

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 :)

@DHowett commented on GitHub (Nov 24, 2025): > 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 :)
Author
Owner

@DHowett commented on GitHub (Dec 3, 2025):

Yep, I'm gonna call this a /duplicate of https://github.com/PowerShell/openssh-portable/pull/806

Thanks!

@DHowett commented on GitHub (Dec 3, 2025): Yep, I'm gonna call this a /duplicate of https://github.com/PowerShell/openssh-portable/pull/806 Thanks!
Author
Owner

@microsoft-github-policy-service[bot] commented on GitHub (Dec 3, 2025):

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!

@microsoft-github-policy-service[bot] commented on GitHub (Dec 3, 2025): 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! <!-- Policy app identification https://img.shields.io/static/v1?label=PullRequestIssueManagement. -->
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#23832