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

how to get alt to send escape? #123

Closed
alok opened this issue Sep 13, 2017 · 13 comments
Closed

how to get alt to send escape? #123

alok opened this issue Sep 13, 2017 · 13 comments

Comments

@alok
Copy link

alok commented Sep 13, 2017

I'm trying to switch from iterm to kitty, except that the alt key in kitty does not work for me inside (neo)vim because it does not seem to send ESC, so mappings like a-s don't work.

@kovidgoyal
Copy link
Owner

Alt most definitely does send escape. Try running

cat

in the terminal and typing

alt+s

You get

^[s

Or if you are on OS X, IIRC the OS converts Alt + key into unicode characters. A bit of googling will show you how to get OS X to stop doing that. I'm not an OS X user so I can't really help with that.

@justinmk
Copy link

justinmk commented Nov 5, 2017

If there's a way to do this in kitty by default on macOS I would strongly suggest doing that.

https://stackoverflow.com/questions/11876485 involves installing software or setting a system-wide setting.

Currently option (alt) chords in kitty on macOS don't do anything useful. E.g. in bash it inserts non-printable bytes--it doesn't show the expected multibyte character.

For comparison:

  • In Terminal.app, with "Use Option as meta key" disabled, alt+o inserts ø (0xF8) in bash.
  • In Terminal.app, with "Use Option as meta key" enabled, alt+o sends ESC + o.
    • Would be nice if kitty behaved like this by default on macOS.
  • In kitty on macOS, alt+o in bash enters some unfinished state, which is then combined with the next keypress. E.g. in bash, nvim <A-o>foo<Enter> edits a file named <b8>foo.

@kovidgoyal
Copy link
Owner

I dont know of any API on macOS that allows applications to prevent the OS from converting alt+keypress into unicode input. So the only way to do it would be to bypass the key handling of GLFW and process the raw scancodes, which is probably what terminal.app does. And then you have to worry about handling people using non-standard keyboard layouts. That's way more work than I care to put in for a platform I dont use. Patches are welcome.

@justinmk
Copy link

justinmk commented Nov 5, 2017

Maybe @gnachman knows :)

@justinmk
Copy link

justinmk commented Nov 5, 2017

@kovidgoyal alacritty issue tracker has some hints, NSEvent.charactersIgnoringModifiers() seems to be the way to get "o" from alt+o. Then that could be combined with the detected ALT modifier.

alacritty/alacritty#62 (comment)

https://github.com/gnachman/iTerm2/blob/c67051d19907e77be670fa04d22d8d5710a0fc62/sources/PTYSession.m#L5817

@kovidgoyal
Copy link
Owner

Thanks, that is essentially the solution I was talking about, bypassing GLFW. That is still a pretty large amount of work, because one has to first bypass glfw and implement key event handler, then remap the key events back to glfw key events. Still, might be worth doing someday.

@kovidgoyal
Copy link
Owner

Turns out that it is possible to at least support the "option as meta" use case without bypassing glfw. Basically you just have to manually handle the case of alt + printable keys instead of relying on glfw. f137ea7

I'd appreciate it if some mac users sould test it out more thoroughly.

@justinmk
Copy link

justinmk commented Nov 7, 2017

@kovidgoyal Wonderful! Is it much trouble to post a dmg?

@kovidgoyal
Copy link
Owner

The dmg is inside the attached zip file because github doesnt allow uploading dmg files.
kitty.zip

@justinmk
Copy link

justinmk commented Nov 7, 2017

@kovidgoyal This works much better than the keymap hack I was using (which had weird interactions with tmux). No problems so far.

(Installing random tools as suggested in https://stackoverflow.com/questions/11876485/ was not a pleasant alternative.)

@kovidgoyal
Copy link
Owner

Glad to hear it :)

justinmk added a commit to justinmk/config that referenced this issue Nov 7, 2017
@kovidgoyal
Copy link
Owner

And it finally turns out that I was completely wrong. It's actually possible to do both unicode input and option as alt without bypassing glfw. 505ae90

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants