I'd like to remap the shift key (⇧) + space (␣) to underscore (_
)
I'd prefer to not have to install any third party tools if possible.
Similar question for windows
I'd like to remap the shift key (⇧) + space (␣) to underscore (_
)
I'd prefer to not have to install any third party tools if possible.
Similar question for windows
The Karabiner code in the 2015 response is now outdated, as Karabiner now uses JSON instead of XML. You can add a custom complex modification by creating a file called ~/.config/karabiner/assets/complex_modifications/my_modification.json and use the following JSON code. Then open the karabinder-Elements app, navigate to "Complex Modifications", and enable the rules you have just added.
{
"title": "Underscore mapping",
"rules": [
{
"manipulators": [
{
"description": "Change left_shift+space to underscore (_).",
"from": {
"key_code": "spacebar",
"modifiers": {
"mandatory" : [
"left_shift"
]
}
},
"to": [
{
"key_code": "hyphen",
"modifiers": [
"left_shift"
]
}
],
"type": "basic"
}
]
},
{
"manipulators": [
{
"description": "Change right_shift+space to underscore (_).",
"from": {
"key_code": "spacebar",
"modifiers": {
"mandatory" : [
"right_shift"
]
}
},
"to": [
{
"key_code": "hyphen",
"modifiers": [
"left_shift"
]
}
],
"type": "basic"
}
]
}
]
}
If you don't want to use a third party tool, you will face a similar problem as the OP in this question (DefaultKeyBinding.dict: Syntax error near unexpected token) that only applications which use the Cocoa text system will support this.
Additionally it appears that the shift ⇧ key can't be properly used as modifier key if shift ⇧+some key doesn't have another representation than an unmodified some key - and shift ⇧+space doesn't have one.
You may either create a DefaultKeyBinding.dict or install Karabiner and configure a custom keycode.
DefaultKeyBinding.dict (only applications which use the Cocoa text system will support this)
Open Terminal and enter:
mkdir ~/Library/KeyBindings
touch ~/Library/KeyBindings/DefaultKeyBinding.dict
Use nano ~/Library/KeyBindings/DefaultKeyBinding.dict
to add (using another shortcut like cmd ⌘ctrl ^space here):
{
"@^ " = ("insertText:", "_");
}
to output an underscore.
Karabiner (all apps should support this)
Enter the customized keycode
<?xml version="1.0"?>
<root>
<item>
<name>Shift Space to Underscore</name>
<appendix>(Change Shift-space to _)</appendix>
<identifier>remap.shiftspace2underscore</identifier>
<autogen>__KeyToKey__ KeyCode::SPACE, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_SHIFT, KeyCode::MINUS, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_SHIFT,</autogen>
</item>
</root>
Save the file