Open ethanmsl opened 2 years ago
I'm not sure this can be handled within Helix since we're only getting what the terminal sends us for keycodes.
If you start up showkey -a
without the fix, what happens when you input Alt-j
? For example on linux:
$ showkey -a
Press any keys - Ctrl-D will terminate this program
^[j 27 0033 0x1b # Alt-j
106 0152 0x6a
^[k 27 0033 0x1b # Alt-k
107 0153 0x6b
^[h 27 0033 0x1b # Alt-h
104 0150 0x68
^[l 27 0033 0x1b # Alt-l
108 0154 0x6c
^J 10 0012 0x0a # Ctrl-j
^K 11 0013 0x0b # Ctrl-k
^H 8 0010 0x08 # Ctrl-h
^L 12 0014 0x0c # Ctrl-l
^C 3 0003 0x03 # Ctrl-c
^D 4 0004 0x04 # Ctrl-d
I'm using linux but I had a similar problem because I configured my left alt key to be used as the level-3 key because I often use level-3 characters on my keyboard layout.
I solved the problem by just mapping the characters that my keyboard layout produces for alt+<something>
:
"ó" = "repeat_last_motion"
"ij" = "expand_selection"
"ú" = "shrink_selection"
"ù" = "select_prev_sibling"
"ø" = "select_next_sibling"
(this is for the EurKEY layout)
showkey
isn't available on mac (in zsh, bash, or fish).Using the 3rd option above:
(Alt := Option)
˙
- 4 / 0x4
∆
- 38 / 0x26
˚
- 40 / 0x28
¬
- 37 / 0x25
…
- 41 / 0x29
` -
4 / 0x4`` -
38 / 0x26`` -
40 / 0x28`` -
37 / 0x25`` -
41 / 0x29`If there's a more useful way to acquire and relay these just lmk.
Actually the best tool to use would be crossterm's event-read example: https://github.com/crossterm-rs/crossterm/blob/09ffd70c30cd28ee06ef6952e40ec5b2b4eaa57f/examples/event-read.rs
That should output the KeyEvents crossterm reads which is what helix is reading.
The characters that @ethanmsl provided are the same ones that show up when I run showkey -a
on Linux via SSH in iTerm2.
It's also what you get by default when typing in any text input on Mac OS. Mac OS just seems to translate the Alt+<key>
presses into other unicode code points.
Here's the whole keyboard:
So for all the Alt-<key>
mappings I can see in the docs, that would give:
[keys.normal]
# Mac Alt-.
"≥" = "repeat_last_motion"
# Mac Alt-` (no way to capture this; Alt-` is the same as `)
# "???" = "switch_to_uppercase"
# Mac Alt-u / Alt-U (no way to capture this; Alt-u is the same as Alt-U)
# "¨" = "earlier"
# "¨" = "later"
# Mac Alt-d
"∂" = "delete_selection_noyank"
# Mac Alt-c
"ç" = "change_selection_noyank"
# Mac Alt-|
"«" = "shell_pipe_to"
# Mac Alt-!
"⁄" = "shell_append_output"
# Mac Alt-s
"" = "split_selection_on_newline"
# Mac Alt-;
"…" = "flip_selections"
# Mac Alt-:
"Ú" = "ensure_selections_forward"
# Mac Alt-,
"≤" = "remove_primary_selection"
# Mac Alt-C
"Ç" = "copy_selection_on_prev_line"
# Mac Alt-(
"·" = "rotate_selection_contents_backward"
# Mac Alt-)
"‚" = "rotate_selection_contents_forward"
# Mac Alt-x
"≈" = "shrink_to_line_bounds"
# Mac Alt-K
"" = "remove_selections"
# Mac Alt-o
"ø" = "expand_selection"
# Mac Alt-i
"ˆ" = "shrink_selection"
# Mac Alt-p
"π" = "select_prev_sibling"
# Mac Alt-n
"˜" = "select_next_sibling"
[keys.insert]
# Mac Alt-d
"∂" = "delete_word_forward"
# Mac Alt-b
"∫" = "move_prev_word_end"
# Mac Alt-f
"ƒ" = "move_next_word_start"
# Mac Alt->
"˘" = "goto_file_end"
# Mac Alt-<
"¯" = "goto_file_start"
EDIT: Hmm... If I use that config (just the [keys.normal
) part, I get:
Bad config: data did not match any variant of untagged enum KeyTrie for key `keys.normal` at line 1 column 1
On further reading this what Helix is doing is the standard for most CLI programs.
Mac Opt
is different than Alt
(with behavior like accenting characters).
And terminal emulators that support macOS (almost?) invariably have a way to map the key code, typically to "Esc+".
I don't know what the practicality would be for Helix to work with both the default and mapped keycodes. But, minus giving explicit optioning support in program, naively the best path would be to retain current behavior, but (much like documentation reccomends a terminal emulator to get 24-bit colors) note that remapping the Opt_key is commonly done in mac terminal environments to access Alt-key short-cuts.
Given that Helix is especially appealing to terminal newcomers [raises hand] -- that bit of documentation will probably help some users.
For (hopefully) helpful reference here is how you remap Opt
in 5 common terminal emulators on macOS.
max_os_opt_as_alt
> uncomment and set to left
, right
, or both
I was not able to quickly find clear documentation for this. By default, testing with Opt+`
in Helix: running the command once did nothing and running it a second time performed the desired action. This seemed to occur regardless of time between key-combo presses, as long as there were no intervening presses. If anyone has info to add on configuring Alacrity keymapping behavior or documentation on the above behavior: please do share. :)
For Alacritty, the main viable option I've seen is doing a bunch of manual mappings, see https://github.com/alacritty/alacritty/issues/62
My 2 cents, when using Use Option as Meta key
in Terminal it solves the problem... but you cannot use option
as compose key anymore, and thus typing accents for example.
On further reading this what Helix is doing is the standard for most CLI programs. Mac
Opt
is different thanAlt
(with behavior like accenting characters). And terminal emulators that support macOS (almost?) invariably have a way to map the key code, typically to "Esc+".I don't know what the practicality would be for Helix to work with both the default and mapped keycodes. But, minus giving explicit optioning support in program, naively the best path would be to retain current behavior, but (much like documentation reccomends a terminal emulator to get 24-bit colors) note that remapping the Opt_key is commonly done in mac terminal environments to access Alt-key short-cuts.
Given that Helix is especially appealing to terminal newcomers [raises hand] -- that bit of documentation will probably help some users.
For (hopefully) helpful reference here is how you remap
Opt
in 5 common terminal emulators on macOS.Opt_key ~~~> ≃Alt_key
iTerm2 (3.4.15) [web reference] : remapping is done via Preferences > Profiles > Keys > General > [radio button interface]
Kitty (0.25.1) [web reference] : remapping is done via Preferences > search for
max_os_opt_as_alt
> uncomment and set toleft
,right
, orboth
WezTerm (20220408-101518-b908e2dd) [unneeded web reference] : Already mapped by default. 👍
Alacritty (0.10.1) [web ≈reference]
- I was not able to quickly find clear documentation for this. By default, testing with
Opt+`
in Helix: running the command once did nothing and running it a second time performed the desired action. This seemed to occur regardless of time between key-combo presses, as long as there were no intervening presses. If anyone has info to add on configuring Alacrity keymapping behavior or documentation on the above behavior: please do share. :)"Terminal" macOS_default (2.12.7) [web reference] : remapping is done via Preferences > Profiles > click button at bottom labelled "Use Option as Meta key"
It would be awesome to see this linked in the documentation somewhere so that newcomers can quickly move past this issue.
+1 with this issue, and using Warp as the terminal app, but can be fixed by setting the preferences as follows:
For Alacritty, I think this is relevant. A six year old issue in Alacritty has just been resolved with an upstream change to winit:
https://github.com/alacritty/alacritty/commit/d9ba129e9e722a551cc0cc4c1899c97593ca26b4
This allows the Option key to behave as Alt. An example alacritty.yml
will look like:
window:
# Make `Option` key behave as `Alt` (macOS only):
# - OnlyLeft
# - OnlyRight
# - Both
# - None (default)
option_as_alt: OnlyLeft
Not released yet, but I'd imagine this will be out in the next version. These are the related issues leading to the change:
https://github.com/alacritty/alacritty/issues/62 https://github.com/rust-windowing/winit/pull/2576
WezTerm (20220408-101518-b908e2dd) [unneeded web reference] : Already mapped by default. 👍
wezterm 20230320-124340-559cb7b0 does not appear to map this by default. I had to add this to my config:
config.send_composed_key_when_left_alt_is_pressed = false
config.send_composed_key_when_right_alt_is_pressed = false
See: https://wezfurlong.org/wezterm/config/keyboard-concepts.html#macos-left-and-right-option-key https://github.com/wez/wezterm/issues/216
@rcorre according to change log 20200620-160318-e00b076c
:
The default behavior on these systems is
send_composed_key_when_left_alt_is_pressed=false
andsend_composed_key_when_right_alt_is_pressed=true
Yielding one that defaults to standard alt (left) and one that does mac option (right) by default. You might be someone that sues right alt and it appear broken or the behavior may have drifted from description (in which case I'd file a bug with Wezterm [behavior could be better documented either way!]
You might be someone that sues right alt and it appear broken
I have control mapped to option, and I'm pressing left control. I guess maybe that sends right-alt somehow?
see also #2469 for some additional discussion
+1 with this issue, and using Warp as the terminal app, but can be fixed by setting the preferences as follows:
For some reason, this does not work for me and even in WezTerm Opt-C does not go up one line (opposite of Shift-C)
For Ghostty: add macos-option-as-alt = left
to your config, alternatively you can set it to right
or true
for both.
Summary
None of the Alt+ (opt+) keys work on Mac.
Combining experiences (from Matrix chat and testing) neither on Intel nor M1 macs. And neither OSX_11 nor OSX_12. And in neither in default_OSX_terminal nor iTerm2.
iTerm2 allows remapping of Alt/Opt to send an escape code instead. Doing this seems to fix it here. (process outlined here:: https://www.clairecodes.com/blog/2018-10-15-making-the-alt-key-work-in-iterm2/). Though I'm not sure if it causes any other issues.
Note: Alt/Opt does not work by default in iTerm2, but it DOES work by default in the default_osXterminal -- however the Alt/Opt+ does not work in Helix in EITHER.
Reproduction Steps
I tried this: Any of the Alt+_ key sequences are sufficient for testing. Alt+` is a simple one, as it sends a selection to uppercase. Alt+. (repeat last motion) is another simple one.
I expected this to happen: The listed commands to work.
Instead, this happened: Standard behavior or nothing. (in cases where a combining mark would be produced (e.g. Alt+` or Alt+u, which create ` or ¨, respectively the highlighted combining mark is produced even though Helix is in Normal_Mode...)
Helix log
2022-04-25T06:08:09.677 helix_view::editor [ERROR] Failed to initialize the LSP for
source.julia
{ cannot find binary path } 2022-04-25T07:45:54.383 helix_view::editor [ERROR] Failed to initialize the LSP forsource.toml
{ LSP not defined } 2022-04-25T21:42:53.303 helix_view::theme [WARN] Theme: invalid style attribute: modifier 2022-04-25T21:43:18.683 helix_view::theme [WARN] Theme: malformed hexcode: fg 2022-04-25T21:43:18.683 helix_view::theme [WARN] Theme: malformed hexcode: form 2022-04-25T21:43:54.696 helix_view::theme [WARN] Theme: malformed hexcode: light-white 2022-04-25T21:44:44.544 helix_view::editor [ERROR] Failed to initialize the LSP forsource.python
{ cannot find binary path } 2022-04-25T21:45:15.281 helix_view::theme [WARN] Theme: malformed hexcode: light-white 2022-04-25T21:46:12.776 helix_view::theme [WARN] Theme: malformed hexcode: foreground 2022-04-25T21:46:12.777 helix_view::theme [WARN] Theme: invalid style attribute: Modifiers 2022-04-25T21:46:12.777 helix_view::theme [WARN] Theme: malformed hexcode: grey3 2022-04-25T21:46:12.777 helix_view::theme [WARN] Theme: malformed hexcode: pink 2022-04-25T21:46:45.319 helix_view::theme [WARN] Theme: invalid style attribute: modifier 2022-04-25T21:47:35.998 helix_view::theme [WARN] Theme: malformed hexcode: light-white 2022-04-25T21:47:48.178 helix_view::theme [WARN] Theme: malformed hexcode: form 2022-04-25T21:47:48.178 helix_view::theme [WARN] Theme: malformed hexcode: fg 2022-04-25T21:48:26.578 helix_view::theme [WARN] Theme: malformed hexcode: light-white 2022-04-25T23:41:49.234 helix_view::editor [ERROR] Failed to initialize the LSP forsource.toml
{ LSP not defined }Platform
macOS
Terminal Emulator
default_Version 2.11 (440) && iTerm2_Build_3.4.15
Helix Version
helix 22.03 (d4e45fd4)