Open
Description
Environment data
AppVeyor Build: 1.0.553
PS version: 5.1.17763.316
PSReadline version: 2.0.0-beta4, **AppVeyor Build: 1.0.553**
os: 10.0.17763.1 (WinBuild.160101.0800)
PS file version: 10.0.17763.1 (WinBuild.160101.0800)
and
PS version: 6.2.0
PSReadline version: 2.0.0-beta4, **AppVeyor Build: 1.0.553**
os: 10.0.17763.1 (WinBuild.160101.0800)
PS file version: 6.2.0
Steps to reproduce or exception report
Enable PSReadLine vi-mode
While in insert-mode press Ctrl+[
and prior behavior was to change to command-mode
Currently, ^[
is rendered in the console and PSReadLine remains in insert-mode.
Activity
gwojan commentedon Apr 30, 2019
So, just to throw another wrinkle, pressing
Ctrl+[
in the PowerShell Integrated Console in VSCode, PowerShell Preview 2.0.2 works as expected.Keep in mind this IS NOT the PSReadLine included with the PowerShell Preview Extension -- it's the same version being used in other "terminals".
daxian-dbw commentedon Jun 3, 2019
@gwojan Did
Ctrl+[
ever work on Windows in the pwsh console with the VI mode?Both 2.0.0-beta.3 and 2.0.0-beta.4 work as you expect (change to command mode) in pwsh on Linux, but on Windows, both don't work while the beta.4 PSReadLine renders
^[
(Ctrl+[
doesn't work in beta.2 either).gwojan commentedon Jun 3, 2019
@daxian-dbw yes, absolutely it worked on Windows PowerShell and pwsh.exe. As a matter of fact, it still works in the VSCode PowerShell Integrated Console just not the standard Windows Console.
daxian-dbw commentedon Jun 3, 2019
@gwojan Then it may be a regression that happened way back ... I just tried with 2.0.0-beta.2, and it doesn't work. Which version did it work for you?
gwojan commentedon Jun 3, 2019
@daxian-dbw The build that I pulled from AppVeyor (Build: 1.0.553) that broke things for me was documented in the original report.
If you'd like I can try to reinstall some of the older builds to identify a working one. 😃
daxian-dbw commentedon Jun 4, 2019
Never mind if you cannot remember the working version that you used before. I will search back to find it out.
gwojan commentedon Jun 4, 2019
@daxian-dbw The last working build I have from AppVeyor is
1.0.508
files dated 2/22/2019. ThePSReadLine.psd1
has this tagged asbeta3
.I also have:
Set-PSReadLineKeyHandler -Chord 'Ctrl+[' -Function ViCommandMode
in my profile.The next version that I still have on my system that actually breaks
Ctrl+[
is1.0.540
files dated 4/17/2019.Ctrl+[
bound-able on Windows #935gwojan commentedon Jun 7, 2019
@daxian-dbw I just pulled build 1.0.15 from AppVeyor and confirmed the
Ctrl+[
binding works again in Windows PowerShell 5.1, PowerShell 6.2 and PowerShell 7. My fingers thank you immensely! 😀 👍daxian-dbw commentedon Jun 10, 2019
@gwojan glad it worked for you, but the PR is still in review and not merged yet, so let's keep this issue open for now.
gwojan commentedon Jun 10, 2019
Thanks @daxian-dbw. 😄 I just noticed this also fixes another issue I was having and forgot to open an issue.
Set-PSReadLineKeyHandler -Key 'Ctrl+{' -Function DeleteLine
This now works like
<ESC>S
to clear the current line.4 remaining items
CurtisDyer commentedon Jul 28, 2020
I can confirm I am having the same issue with 2.1.0-beta2. I have the issue in Windows Terminal 1.1, 1.2 Preview, and conhost environments (PS 5.1 and PS 7.0.3).
However, it does work in VS Code terminal (PS 5.1).
Windows Version: 1909, Build 18363.959
parkovski commentedon Sep 10, 2021
Current workaround is to find the OEM scan code for your
[
key and use the name for it fromSystem.ConsoleKey
, it works for me asCtrl+Oem4
.CurtisDyer commentedon Sep 10, 2021
This workaround resolved the issue for me. Thank you for sharing!
[-]Ctrl+[ in vi insert mode no longer acts as escape changing to command-mode[/-][+]"Ctrl+[" is not bondable as a key chord in PSReadLine[/+]andyleejordan commentedon Jan 30, 2023
I can at least shed some light on why this is so broken, or really, why it's often broken and then sometimes seemingly not broken, with no easy permanent fix. The key combination
Ctrl+[
isEsc
, as in, it's supposed to send ASCII code 27 just as pressing the escape key does. Historically that key chord is one and the same as the escape key. But nowadays there's a whole of lot of "things" in between the keyboard and PSReadLine finally receiving they key (I'm mostly talking about .NET's ownSystem.Console.ReadKey
implementation, but also relevant are different terminal emulators). In fact on macOS and Linux, where .NET is quite a bit "newer" and understands ASCII codes fairly well, and the terminal emulators are pretty standard, you can run[Console]::ReadKey()
in PowerShell, pressCtrl+[
, and you'll get:So on PSReadLine's side, setting up a binding to listen the simultaneous press of the keys
Ctrl
and[
probably isn't going to work, because the keyboard driver won't send it, it'll sendEsc
. At least that behavior though is predictable and we could special caseSet-PSReadLineKeyHandler -Chord 'Ctrl+['
to be understood as listening for escape.But Windows is where the trouble especially lies, it doesn't follow the same rules. The same experiment on an up-to-date Windows with the latest Terminal app:
Which at least explains why binding
Ctrl+Oem4
works (for most people). It should beEsc
, with no modifier key, but with however .NET is implemented, and however the particular Windows terminal is behaving, this does different things!Repeating the experiment, on Windows, but this time using a terminal in VS Code (which is based off Xterm.js) instead of the Windows Terminal app, watch:
That's right! And on Windows. But so inconsistent as to produce this bug. What gives? 🤷 There's a lot of places this could be "wrong" in different ways and therefore "fixed" and it's hard to say what's right.
Ctrl+Oem4
asEscape
on Windows, and also interpret the bindingCtrl+[
asEsc
.Ctrl+Oem4
asEscape
on WindowsCtrl+Oem4
and instead sendEscape
(like Xterm.js and every terminal you'll find on macOS and Linux)We've been dealing with "weird" unexpected things like this due to the historical evolution of keyboard input ever since we first got
Console.ReadKey()
working on .NET Core so we could implement PSReadLine. It's complicated!xdhmoore commentedon Jun 9, 2023
For me the
Ctrl+Oem4
-based key handler works when I am in insert mode. But when I am in normal or command mode or whatever it's called, theCtrl+[
chord outputs^[
to the terminal.I'm wondering if theViCommandMode
function passes through the key command when you are already in command mode. This seems like it could be related to the behavior ofEsc
. When I pressEsc
in insert mode, it changes me to command mode. But when I press it in command mode, it issues a beep. The beep is the same behavior as Vim, but I wonder if the layering here that works for Escape is not working correctly forCtrl+Oem4
. Just a theory.I'm using Windows Terminal.
Nevermind, the following addition seems to have solved it:
CNLHC commentedon Sep 25, 2024
Set-PSReadLineKeyHandler -Chord 'Ctrl+Oem4' -Function ViCommandMode
works for me