Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xcpky opened this issue Apr 2, 2023 · 21 comments · May be fixed by #7020
Open

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

xcpky opened this issue Apr 2, 2023 · 21 comments · May be fixed by #7020
Labels
A-helix-term Area: Helix term improvements C-enhancement Category: Improvements

Comments

@xcpky
Copy link

xcpky commented Apr 2, 2023

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
Copy link
Member

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
Copy link

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
Copy link

mk-f commented Apr 11, 2023

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
Copy link

jaese commented Apr 18, 2023

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
Copy link

timka commented Apr 27, 2023

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
Copy link

n8henrie commented May 9, 2023

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
Copy link
Member

pascalkuthe commented May 9, 2023

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
Copy link

sdemura commented Jun 6, 2023

@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
Copy link

soifou commented Jun 6, 2023

@sdemura, almost :) what you want is:

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

@xcpky
Copy link
Author

xcpky commented Jun 6, 2023

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

@samuelstevens
Copy link

[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
Copy link
Member

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
Copy link

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
Copy link
Member

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.

djpowers added a commit to djpowers/dotfiles that referenced this issue Sep 19, 2023
- use familiar ctrl + [ (left bracket) mapping
- see helix-editor/helix#6551 for discussion
@teancom
Copy link

teancom commented Dec 21, 2023

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
Copy link

kj commented Dec 28, 2023

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
Copy link

geo-ant commented Jan 5, 2024

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

  • In his book Practical Vim, p.30 author Drew Neil recommends mapping caps lock to ctrl and using C-[ as escape. Quote: "The C-[ mapping is synonymous with Esc , and it’s easier to type when the Ctrl key is within easy reach."
  • In his talk Stop Writing Deap Programs around the 18:00 minute mark, Jack Rusher says he still maps caps lock to control because it makes his life easier on unix machines (and gives an interesting historical reason for that :) )

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

@kj
Copy link

kj commented Jan 6, 2024

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

[control]
[ = esc

@webdev23
Copy link

webdev23 commented Jan 12, 2024

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
Copy link

wrl commented Feb 6, 2024

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
Copy link

webdev23 commented Feb 7, 2024

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.

srstevenson added a commit to srstevenson/dotfiles that referenced this issue Aug 18, 2024
This is required due to a regression in Helix 23.03, reported at
helix-editor/helix#6551
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-enhancement Category: Improvements
Projects
None yet
Development

Successfully merging a pull request may close this issue.