Last active
September 15, 2024 09:19
-
-
Save mykolaharmash/51846c538c5703de67ad15e6e3109ba0 to your computer and use it in GitHub Desktop.
Hammerspoon Vim Navigation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- put into ~/.hammerspoon | |
-- map Caps Lock key to Control in macOS settings (Keyboard -> Modifier Keys...) | |
-- Give all the accessability permissions in Hammerspoon preferences | |
-- NOTE: Changing "Key repeat rate" and "Delay until repeat" in macOS settings | |
-- require Hammerspoon restart to pick up those changes. | |
-- See: https://github.com/Hammerspoon/hammerspoon/issues/3264 | |
local function pressFn(mods, key) | |
if key == nil then | |
key = mods | |
mods = {} | |
end | |
return function() hs.eventtap.keyStroke(mods, key, 1000) end | |
end | |
local function remap(mods, key, pressFn) | |
hs.hotkey.bind(mods, key, pressFn, nil, pressFn) | |
end | |
remap({'ctrl'}, 'd', pressFn('pagedown')) | |
remap({'ctrl'}, 'u', pressFn('pageup')) | |
remap({'ctrl', 'shift'}, 'd', pressFn({'shift'}, 'pagedown')) | |
remap({'ctrl', 'shift'}, 'u', pressFn({'shift'}, 'pageup')) | |
remap({'ctrl'}, 'h', pressFn('left')) | |
remap({'ctrl'}, 'j', pressFn('down')) | |
remap({'ctrl'}, 'k', pressFn('up')) | |
remap({'ctrl'}, 'l', pressFn('right')) | |
remap({'ctrl', 'cmd'}, 'h', pressFn({'cmd'}, 'left')) | |
remap({'ctrl', 'cmd'}, 'j', pressFn({'cmd'}, 'down')) | |
remap({'ctrl', 'cmd'}, 'k', pressFn({'cmd'}, 'up')) | |
remap({'ctrl', 'cmd'}, 'l', pressFn({'cmd'}, 'right')) | |
remap({'ctrl', 'alt'}, 'h', pressFn({'alt'}, 'left')) | |
remap({'ctrl', 'alt'}, 'j', pressFn({'alt'}, 'down')) | |
remap({'ctrl', 'alt'}, 'k', pressFn({'alt'}, 'up')) | |
remap({'ctrl', 'alt'}, 'l', pressFn({'alt'}, 'right')) | |
remap({'ctrl', 'shift'}, 'h', pressFn({'shift'}, 'left')) | |
remap({'ctrl', 'shift'}, 'j', pressFn({'shift'}, 'down')) | |
remap({'ctrl', 'shift'}, 'k', pressFn({'shift'}, 'up')) | |
remap({'ctrl', 'shift'}, 'l', pressFn({'shift'}, 'right')) | |
remap({'ctrl', 'shift', 'cmd'}, 'h', pressFn({'shift', 'cmd'}, 'left')) | |
remap({'ctrl', 'shift', 'cmd'}, 'j', pressFn({'shift', 'cmd'}, 'down')) | |
remap({'ctrl', 'shift', 'cmd'}, 'k', pressFn({'shift', 'cmd'}, 'up')) | |
remap({'ctrl', 'shift', 'cmd'}, 'l', pressFn({'shift', 'cmd'}, 'right')) | |
remap({'ctrl', 'shift', 'alt'}, 'h', pressFn({'shift', 'alt'}, 'left')) | |
remap({'ctrl', 'shift', 'alt'}, 'j', pressFn({'shift', 'alt'}, 'down')) | |
remap({'ctrl', 'shift', 'alt'}, 'k', pressFn({'shift', 'alt'}, 'up')) | |
remap({'ctrl', 'shift', 'alt'}, 'l', pressFn({'shift', 'alt'}, 'right')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment