Skip to content

Instantly share code, notes, and snippets.

@handcoding
Created July 9, 2020 22:37
Show Gist options
  • Save handcoding/df4302ecb15f2aba3becb296551d94ce to your computer and use it in GitHub Desktop.
Save handcoding/df4302ecb15f2aba3becb296551d94ce to your computer and use it in GitHub Desktop.
Excel keyboard shortcut remappings to make it more Mac like (via Karabiner classic)
<item>
<name>Excel: Command+Left and Command+Right to move within cells</name>
<appendix>For some reason, Excel wants you to use Home (and presumably End) to move to the beginning or end of a line within a cell, which is bogus.</appendix>
<appendix>This also remaps Command+Up and Command+Down so that they move the cursor to the top or bottom of the current cell.</appendix>
<identifier>private.excel_fix_command_arrow_keys</identifier>
<only>EXCEL</only>
<windowname_only>Excel_Window</windowname_only>
<uielementrole_only>AXTextArea, AXTextField</uielementrole_only>
<!-- Command+Left and Command+Right to move within cells in Excel -->
<autogen>
__KeyToKey__
KeyCode::CURSOR_LEFT, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_COMMAND,
KeyCode::HOME
</autogen>
<autogen>
__KeyToKey__
KeyCode::CURSOR_RIGHT, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_COMMAND,
KeyCode::END
</autogen>
<!-- Shift+Command+Up and Shift+Command+Down to Shift+Command+Home and Shift+Command+End to select to the top/bottom of the cell within Excel -->
<!-- See also this note about ordering within Karabiner:
https://pqrs.org/osx/karabiner/xml.html.en#order -->
<autogen>
__KeyToKey__
KeyCode::CURSOR_UP, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_COMMAND | MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_SHIFT,
KeyCode::HOME, ModifierFlag::COMMAND_L | ModifierFlag::SHIFT_L
</autogen>
<autogen>
__KeyToKey__
KeyCode::CURSOR_DOWN, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_COMMAND | MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_SHIFT,
KeyCode::END, ModifierFlag::COMMAND_L | ModifierFlag::SHIFT_L
</autogen>
<!-- Command+Up and Command+Down to move to the top/bottom of the cell within Excel -->
<autogen>
__KeyToKey__
KeyCode::CURSOR_UP, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_COMMAND | ModifierFlag::NONE,
KeyCode::HOME, ModifierFlag::COMMAND_L
</autogen>
<autogen>
__KeyToKey__
KeyCode::CURSOR_DOWN, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_COMMAND | ModifierFlag::NONE,
KeyCode::END, ModifierFlag::COMMAND_L
</autogen>
</item>
<item>
<name>Excel: Fix the shortcut keys while you’re in a grid view</name>
<appendix>* Allow pressing Enter to edit a cell: As long as you’re not inside a cell, this maps Enter to F2.</appendix>
<appendix>* If you’re not inside a cell, this also remaps Command+Left and Command+Right to Option+PageUp and Option+PageDown.</appendix>
<identifier>private.excel_fix_grid_view</identifier>
<only>EXCEL</only>
<windowname_only>Excel_Window</windowname_only>
<!-- This ensures that these key remappings don’t happen when you’re editing a cell. via: https://pqrs.org/osx/karabiner/xml.html.en#uielementroledef -->
<uielementrole_only>AXTable, AXLayoutArea</uielementrole_only>
<!-- Excel’s shortcut keys via: https://support.office.com/en-us/article/Keyboard-shortcuts-in-Excel-2016-for-Mac-acf5419e-1f87-444d-962f-4e951a658ccd -->
<!-- Enter to F2 to edit cells in Excel (as long as you’re not inside a cell) -->
<autogen>
__KeyToKey__
KeyCode::RETURN, ModifierFlag::NONE,
KeyCode::F2
</autogen>
<!-- Command+Left and Command+Right to left or right a page -->
<autogen>
__KeyToKey__
KeyCode::CURSOR_LEFT, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_COMMAND,
KeyCode::PAGEUP, ModifierFlag::OPTION_L
</autogen>
<autogen>
__KeyToKey__
KeyCode::CURSOR_RIGHT, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_COMMAND,
KeyCode::PAGEDOWN, ModifierFlag::OPTION_L
</autogen>
<!-- Command+Up and Command+Down to move up or down a page -->
<autogen>
__KeyToKey__
KeyCode::CURSOR_UP, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_COMMAND | ModifierFlag::NONE,
KeyCode::PAGEUP
</autogen>
<autogen>
__KeyToKey__
KeyCode::CURSOR_DOWN, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_COMMAND | ModifierFlag::NONE,
KeyCode::PAGEDOWN
</autogen>
</item>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment