helix-editor / helix

A post-modern modal text editor.
https://helix-editor.com
Mozilla Public License 2.0
34.03k stars 2.52k forks source link

Ctrl + [ doesn't function as Escape in helix 23.03 #6551

Open xcpky opened 1 year ago

xcpky commented 1 year ago

I think this is because of the new enhanced keyboard protocol enabled in 23.03. Is there a way to disable it? Although I can remap Ctrl+[ to mode change command, escape has more functions than only mode change. For example, when you enter : to type command, you can't return back to normal mode using Ctrl+[. And there is no way to remap a key combination to a specific keycode in helix, which is available in vim.

the-mikedavis commented 1 year ago

Yeah, the enhanced keyboard protocol change was breaking if you are relying on ambiguous keycodes like C-[. IMO you should not rely on these ambiguous keycodes because it's essentially coincidence that they worked in the first place. And I don't like adding a config option for this since I think the use-case is very niche. Ideally this should be fixed by allowing remapping Escape in the remaining places where it is hard-coded (#5505).

On the other hand though, this could be covered by a config option which overrides the detection, true to assume the protocol is supported and false to assume not. (This has been discussed previously but I can't find the issue.)

wvwwvwwv commented 1 year ago

Ctrl + [ is the de facto standard esc alternative on macOS, and I don't think the usage is niche, because Ctrl + [ is especially useful when your keyboard does not have an esc key (which is true for many Mac/iPad users). I'm really looking forward to the upcoming esc remapping feature.

mk-f commented 1 year ago

I also don't think that using ctrl+[ as esc is a niche use-case, on keyboards with us-layout it is more comfortable to reach (both pinkies) than the actual esc.

For what it's worth you can run hx inside tmux for the moment as a workaround.

jaese commented 1 year ago

These two other control character mappings, backspace ctrl-h and line feed ctrl-j, are still supported after the enhanced keyboard protocol change, so I don't think it is a stretch to keep supporting ctrl-[ as escape by default.

timka commented 1 year ago

helix 23.03 (3cf03723) on OS X 12.6.4.

Not sure if this is related or not, but I'm having a similar issue. ctrl-m doesn't work in helix as line feed in Iterm2, kitty and alacritty, but does work in wezterm and Terminal at least in insert mode. ctrl-j doesn't work in command mode in any of these terms. showkey -a reports ctrl-m as <CTL-J=LF> in all these terms. In general in all of them ctrl-m works just fine (shell, vim).

Is there anything else I could do to provide more details to diagnose the issue? Thanks!

n8henrie commented 1 year ago

With neither ctrl-c or ctrl-[ working for this purpose, I'm left having to leave my home row to exit insert mode (via Esc). Is this by design, or am I missing a recommended alternative?

pascalkuthe commented 1 year ago

you can always rebind the keymapping in your own config. The enhanced keyboard protocol simply allows disambiguating more keys (like c-[ and esc). The default mapping is esc. The fact that c-[ worked by default was merely an accident. but you can easily restore the mapping

sdemura commented 1 year ago

@pascalkuthe can you provide an example?

❯ hx
Bad config: TOML parse error at line 19, column 9
   |
19 | "C-[" = "esc"
   |         ^^^^^
No command named 'esc
soifou commented 1 year ago

@sdemura, almost :) what you want is:

[keys.insert]
  "C-[" = "normal_mode"
xcpky commented 1 year ago

but this workaround can't substitute all the esc usage with 'Ctrl-[', so a feature of keycode remapping should be the best solution.

samuelstevens commented 1 year ago
[keys.insert]
"C-[" = "normal_mode"

This doesn't work for me with helix 23.05 (7f5940be) on Ubuntu 22.04 in tmux. It works outside of tmux, but not inside. Any advice?

pascalkuthe commented 1 year ago

Termux does not support the kitty enhanced keyboard protocol which allows disambiguation of these keycodes. Since terminal multiplexers essentially function as a terminal proxy they must support all of the features of the host terminal (that the user wants to use)

samuelstevens commented 1 year ago

If tmux doesn't support the disambiguation of ctrl-[ and esc, then shouldn't ctrl-[ work as esc in helix? or am I misunderstanding something?

the-mikedavis commented 1 year ago

You can check whether it's enabled by checking the log when running in verbose mode: https://github.com/helix-editor/helix/wiki/Terminal-Support#enhanced-keyboard-protocol

It sounds to me like tmux is probably eating the keycode.

teancom commented 11 months ago

Came here as someone who has been evangelizing mapping CAPS LOCK to CTRL and then using ctrl-[ in vim for over 20 years now. Specifically as someone who has RSI issues and is able to use caps_lock-[ with two very subtle finger movements vs. any alternative. If it was a mere accident that that worked, it's an accident that was true for every combination of vi/vim/nvim/etc. in every terminal emulator and every operating system I've ever used.

kj commented 11 months ago

Yes I agree, I think all of this talk of C-[ being an accident is a little dismissive. Perhaps it was an 'accident' once but its usage is certainly not niche (as this issue proves). The reality is that many people expect and rely on this behaviour. This just hit me today as Alacritty 0.13.0 now implements the kitty keyboard protocol.

geo-ant commented 11 months ago

Hi, just came here to say hat I love helix, and wanted to voice my support that mapping control to caps lock and using C-[ is not a niche use case and should please have first class support. Since I am just some guy on the internet, I'll try to supplement my argument with some appeals to authority in hopes that this rhetorical flourish will convince people :)

I can also try and hop on to help with the implementation if this is a resource issue.

kj commented 10 months ago

In case it helps anyone… until Helix supports this, using keyd to map C-[ to escape seems to work.

[control]
[ = esc
webdev23 commented 10 months ago

There is a couple of settings in ~/.tmux.conf that affects the behavior of the escape sequence, and may help with this issue.

In particular the following:

set -sg escape-time 0


In Helix, found the following mapping to be particularly efficient: Ctrl + space

[keys.insert]                                                             
C-space = "normal_mode"    

[keys.normal]
C-space = "insert_mode" 

[keys.select]
C-space = "normal_mode"     
wrl commented 9 months ago

My C-[ muscle memory is so strong that I also do it at prompts and in pickers, which are not currently re-mappable in Helix (that I can find, at least). Would be nice to have it mapped there too.

webdev23 commented 9 months ago

To advocate for Ctrl + [ users.

They are in their right to notice, this is a very old behavior in VT100 terminal that Ctrl+ [ does produce the escape sequence.

To verify that, we may simply use cat:

cat We press Escape That does print ^[ Now we press Ctrl + [ That does also print ^[

Further documentations can be found with keywords: control-escape sequence VT100

I do personally, as a non-Qwerty keyboard user, have to use the key combo Ctrl + AltGr + 4 to output Ctrl + [.

However I do warmly recommend that Helix supports Ctrl + [ as the escape sequence due to legacy reasons.