Skip to content

Instantly share code, notes, and snippets.

@jamietre
Last active February 16, 2024 10:51
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jamietre/6457204045dce85476a693d21142edc3 to your computer and use it in GitHub Desktop.
Save jamietre/6457204045dce85476a693d21142edc3 to your computer and use it in GitHub Desktop.
Karabiner Elements config to map home/end keys to PC-like behavior on MacOS X
{
"title": "MacOS -> PC Shortcuts",
"rules": [
{
"description": "Top/bottom of document (ctrl+home/ctrl+end)",
"manipulators": [
{
"type": "basic",
"from": <%= from("home", ["command"], ["any"]) %>,
"to": <%= to([["up_arrow", ["left_command"]]]) %>,
"conditions": [ <%= frontmost_application_unless(["remote_desktop", "virtual_machine"]) %> ]
},
{
"type": "basic",
"from": <%= from("end", ["command"], ["any"]) %>,
"to": <%= to([["down_arrow", ["left_command"]]]) %>,
"conditions": [ <%= frontmost_application_unless(["remote_desktop", "virtual_machine"]) %> ]
}
]
},
{
"description": "Home/end keys to the beginning/end line",
"manipulators": [
{
"type": "basic",
"from": <%= from("home", [], ["any"]) %>,
"to": <%= to([["a", ["left_control"]]]) %>,
"conditions": [ <%= frontmost_application_unless(["remote_desktop", "virtual_machine"]) %> ]
},
{
"type": "basic",
"from": <%= from("end", [], ["any"]) %>,
"to": <%= to([["e", ["right_control"]]]) %>,
"conditions": [ <%= frontmost_application_unless(["remote_desktop", "virtual_machine"]) %> ]
}
]
},
{
"description": "Move by word (command+right/command+left)",
"manipulators": [
{
"type": "basic",
"from": <%= from("right_arrow", ["command"], ["any"]) %>,
"to": <%= to([["right_arrow", ["left_option"]]]) %>,
"conditions": [ <%= frontmost_application_unless(["remote_desktop", "virtual_machine"]) %> ]
},
{
"type": "basic",
"from": <%= from("left_arrow", ["command"], ["any"]) %>,
"to": <%= to([["left_arrow", ["left_option"]]]) %>,
"conditions": [ <%= frontmost_application_unless(["remote_desktop", "virtual_machine"]) %> ]
}
]
},
{
"description": "Swap Control <-> Command unless in virtual machine/remote desktop",
"manipulators": [
{
"type": "basic",
"from": <%= from("left_control", [], ["any"]) %>,
"to": <%= to([["left_command"]]) %>,
"conditions": [ <%= frontmost_application_unless(["remote_desktop", "virtual_machine"]) %> ]
},
{
"type": "basic",
"from": <%= from("left_command", [], ["any"]) %>,
"to": <%= to([["left_control"]]) %>,
"conditions": [ <%= frontmost_application_unless(["remote_desktop", "virtual_machine"]) %> ]
},
{
"type": "basic",
"from": <%= from("right_control", [], ["any"]) %>,
"to": <%= to([["right_command"]]) %>,
"conditions": [ <%= frontmost_application_unless(["remote_desktop", "virtual_machine"]) %> ]
},
{
"type": "basic",
"from": <%= from("right_command", [], ["any"]) %>,
"to": <%= to([["right_control"]]) %>,
"conditions": [ <%= frontmost_application_unless(["remote_desktop", "virtual_machine"]) %> ]
}
]
}
]
}
@jamietre
Copy link
Author

jamietre commented Dec 26, 2017

This gist makes a mac keyboard behave like a PC keyboard, using Karabiner Elements, with complex configs for:

  • Home/End to beginning/end of line
  • Ctrl+Home/Ctrl+End to beginning/end of doc
  • Swap Command/Control

All are inactive when running remote desktop apps.

For the last one: On PC we don't use command (windows) key much, most common operations are the same as the mac Command version. Exception is Ctrl+C. I just got used to using Command+C to terminate in a shell; it kind of makes more sense than the overloaded Ctrl+C (for copying) on a PC anyway, so I use command key for all control sequences in a shell.

To build:

  1. clone https://github.com/pqrs-org/KE-complex_modifications/
  2. Copy this to ./src/json
  3. run make
  4. Copy ./docs/json/pc-rules.json ./public/json/pc-rules.json to ~/.config/karabiner/assets/complex_modifications/
  5. Open ke prefs & click 'complex modifications' tab; you should see these there, add them.

@darkdreamingdan
Copy link

Note, i just tried this. You have to name the file pc-rules.json.erb when placing it into ./src/json rather than just having an .erb extension. Otherwise the output json will not be generated.

@dwatrous
Copy link

I tried this, but I can't see them in the Complex Modifications tab.

➜  KE-complex_modifications git:(master) ✗ make
bash scripts/update-json.sh
check docs/json/pc-rules.json
ok
docs/json/pc-rules.json
ruby scripts/lint-groups.rb
(cd docs && ruby ../scripts/make-distjs.rb > dist.json)

I did try restarting karabiner elements, but they still aren't there.

@agarthetiger
Copy link

agarthetiger commented Aug 6, 2019

@dwatrous In the Complex Modifications tab you need to click the Add Rule button and the new rules will be visible there. The GUI only shows enabled rules with a button to remove them, the Add Rule popup lists the new rules with a button to Enable them. This caught me out too initially. The readme in the cloned repository is more up-to-date than this gist and does now mention this.

@webmobiles
Copy link

webmobiles commented Sep 20, 2019

end is working, but not key "home"... i use MacOs Mojave, Karabiner last version

you don't need really this json, is already on 'pc-style' on included on:
https://github.com/pqrs-org/KE-complex_modifications/

@feather-jmalone
Copy link

the home/end keys on my logitech mx keyboard were driving me insane on my mac (11.5.2 big sur). for example, when editing a web-based textarea like this one, the home and end keys would act like page up and page down, making the whole webpage suddenly jolt up or down instead of just moving the inline cursor to the start or end of the line.

needless to say i really appreciate this snippet and the discussion! i followed the original instructions, accounted for the .json.erb file extension, and was able to reconfigure the keys in just a few minutes. thank you!

@monkpit
Copy link

monkpit commented Mar 22, 2022

Note that (as of this writing) the docs folder has changed to be named public. So, you have to put pc-rules.json.erb in src/json and then the output will be in public/json/pc-rules.json.

@jamietre
Copy link
Author

Note that (as of this writing) the docs folder has changed to be named public. So, you have to put pc-rules.json.erb in src/json and then the output will be in public/json/pc-rules.json.

Updated with the old version there too for historical purposes. I don't use a mac anymore at work so I can't test anything ;)

@abondarev84
Copy link

can anybody that already ran this post the resulting json please?

@herself
Copy link

herself commented Feb 16, 2024

As of writing, this doesn't seem to work. Looks like the original repo lost its ability to compile ruby template files...
The workaround I ended up with is to simply use the "PC-Style Shortcuts" that can be imported into Karabiner from its own UI. They have all the shortcuts included in this gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment