Kitty: OSX ctrl cmd swapped - way to swap in kitty too?

Created on 17 Oct 2018  路  14Comments  路  Source: kovidgoyal/kitty

Hi,

since I have ctrl and cmd swapped in the whole system I wonder, if there is the possibility to swap them in the kitty config as well (since I would need to use CMD+C in order to issue a Ctrl+C console behaviour). Haven't found anything so far.

I tried remapping them directly with the glfw keys (swapped 0x2 and 0x8 here) without success.
on_key_input: glfw key: 347 native_code: 0x36 action: PRESS mods: 0x2 text: ''
on_key_input: glfw key: 341 native_code: 0x3b action: PRESS mods: 0x8 text: ''

Is this somehow possible
viennaa

Most helpful comment

@kovidgoyal Of course! I'm happy to explain. I feel the same way as @sergei-dyshel, but would like to give a few reasons of my own:

  • Reason 1

    • It's a relatively common thing to want do since they keys are in the same position and serve a similar function to Ctrl on other keyboards and in other operating systems.

  • Reason 2

    • Different people prefer different hands to hit the modifier key. I (and probably many others) prefer the right hand due to years of muscle memory, and there is no corresponding Ctrl key on that side

  • Reason 3

    • Ctrl is very awkward to hit on Apple keyboards; it is not the same priority as cmd for reasons @sergei-dyshel mentioned. It requires you to curl your thumb and lift your hand, and is very inconvenient, especially to people with years of experience hitting Ctrl on standard keyboards. And I use it a lot as a heavy tmux / vim user

I hope that explains my rationale. iterm2 provides this ability for probably similar reasons, but I really like Kitty, and would like this option there. I think it would make a very useful configuration option. Of course I don't believe it should be on by default! :)

@sergei-dyshel: I'm aware of Karabiner, but that is way too heavy of a tool for this use, and I've had trouble getting it to work.

As for Kitty, I don't know the codebase well enough to know how much work it would be to make it a configuration option. That's why I mentioned @kovidgoyal. I was hoping to at least get some guidance on doing this the right way. I understand if it's not something he uses or wants to take the time to do, but at least some kind of guidance would be helpful so we can give back instead of just maintaining personal hacks.

All 14 comments

You cannot remap modifiers in kitty, I'm afraid. The closest you can
come is mapping entire keypresses, which you will have to do for all
keypresses to have that affect. It should also be a fairly simple thing
to atch kitty to do what you need, see keys.c in the kitty source code

FYI, I've made a simple patch to address this problem, see 056c124f

@kovidgoyal, is there any way you would be able to take a look at the latest patch from @sergei-dyshel and see if there's a way to make this configurable? It does exactly what I want, and it would be amazing to offer it to everyone. https://github.com/kovidgoyal/kitty/commit/a076d0cd8cae0f1a177fc93bd53e0d19bf1f67a9

Not something I am interested in personally, sorry.
It might help if you explained the need for it.

Here's my vision of why one would like to swap Cmd and Ctrl on Mac:

On Linux (and Window) Ctrl and to lesser extent Alt are used as application modifiers (i.e. most application keybindings use combination of Ctrl and Alt), so one could call Ctrl the primary modifier and Alt a secondary one. On the other side Windows(aka Super) is mostly used as global modifier, i.e. for OS-level tasks, window management, global shortcuts.

On MacOS the situation is more complex, since Ctrl is also used for application-level bindings but there still seem to be a concept of Cmd being the primary modifier, Option (aka Alt) being the secondary modifier and Ctrl is used for global tasks but also for application.

So according to my "classification" ctrl and cmd already have swapped roles for one comming from Linux/Windows world and it might make sense to use Cmd as main modifier in terminal too, i.e. for the Ctrl key.

But this is only my personal option and I understand that my patch is just a dirty hack and implementing this feature properly would require much more dev effort so I fully agree with @kovidgoyal's stance.

@flowchartsman
There is an app called Karabiner which allows to remap any keys on per-app basis so you might try this instead of patching Kitty's code. I would do that too but I just have this fetish of patching open-source software 馃槃

@kovidgoyal Of course! I'm happy to explain. I feel the same way as @sergei-dyshel, but would like to give a few reasons of my own:

  • Reason 1

    • It's a relatively common thing to want do since they keys are in the same position and serve a similar function to Ctrl on other keyboards and in other operating systems.

  • Reason 2

    • Different people prefer different hands to hit the modifier key. I (and probably many others) prefer the right hand due to years of muscle memory, and there is no corresponding Ctrl key on that side

  • Reason 3

    • Ctrl is very awkward to hit on Apple keyboards; it is not the same priority as cmd for reasons @sergei-dyshel mentioned. It requires you to curl your thumb and lift your hand, and is very inconvenient, especially to people with years of experience hitting Ctrl on standard keyboards. And I use it a lot as a heavy tmux / vim user

I hope that explains my rationale. iterm2 provides this ability for probably similar reasons, but I really like Kitty, and would like this option there. I think it would make a very useful configuration option. Of course I don't believe it should be on by default! :)

@sergei-dyshel: I'm aware of Karabiner, but that is way too heavy of a tool for this use, and I've had trouble getting it to work.

As for Kitty, I don't know the codebase well enough to know how much work it would be to make it a configuration option. That's why I mentioned @kovidgoyal. I was hoping to at least get some guidance on doing this the right way. I understand if it's not something he uses or wants to take the time to do, but at least some kind of guidance would be helpful so we can give back instead of just maintaining personal hacks.

BTW, I'd like to add that Karabiner rule would swap modifiers for system keybindings too, i.e. if you have cmd+space binding for Spotlight and you swap ctrl and cmd in Karabiner for kitty/iterm2, than you will have to press ctrl+space in those apps for Spotlight. Unfortunately iterm2 built-in modifier remapping works in the same manner (probably utilising same low-level mechanism).
This behaviour is very annoying.... So I would say that the remapping I did in kitty's code is the only proper solution existing on Mac terminals 馃槃

I'm fine with a patch adding such an (off-by-default) option, I'm just not motivated enough to come up with one myself.

@kovidgoyal, thank you for directing me to this issue

+1 to everything in this issue

@kovidgoyal Understood. Would you be willing to provide a little direction on me or @sergei-dyshel integrating this the proper way? Anything we should be aware of? I'll take a crack at it.

Feel free to ask if you have questions, in general, this will need to be
done at the level of glfw, not kitty, since you will also have to remap
the cocoa global menu shortcuts. You define options in config_data.py
and state.[ch] and you will need to create a glfwinithint which the
kitty code in create_os_window() will need to set based onthe option
when creating the first window.

I'm a very big fan of kitty, but unfortunately, lack of this feature on mac is preventing me to use it, I see a lot of people on blogs are struggling with this. I hope you change your mind @kovidgoyal.

@ultrox
You can use the patch I posted here earlier. It does the job pretty well.

@sergei-dyshel will try that, thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

crocket picture crocket  路  4Comments

Jomik picture Jomik  路  4Comments

atomsymbol picture atomsymbol  路  3Comments

bewzaalex picture bewzaalex  路  3Comments

lazarcf picture lazarcf  路  4Comments