Skip to content

Instantly share code, notes, and snippets.

@e-mon
Created May 15, 2017 15:01
Show Gist options
  • Save e-mon/ca6bde4aef9c384d7e10ff5f934c76e4 to your computer and use it in GitHub Desktop.
Save e-mon/ca6bde4aef9c384d7e10ff5f934c76e4 to your computer and use it in GitHub Desktop.
vim-like keybind for hammerspoon
local function keyCode(key, modifiers)
modifiers = modifiers or {}
return function()
hs.eventtap.event.newKeyEvent(modifiers, string.lower(key), true):post()
hs.timer.usleep(1000)
hs.eventtap.event.newKeyEvent(modifiers, string.lower(key), false):post()
end
end
local function keyCodeSet(keys)
return function()
for i, keyEvent in ipairs(keys) do
keyEvent()
end
end
end
local function remapKey(modifiers, key, keyCode)
hs.hotkey.bind(modifiers, key, keyCode, nil, keyCode)
end
-- カーソル移動
remapKey({'ctrl'}, 'h', keyCode('left'))
remapKey({'ctrl'}, 'j', keyCode('down'))
remapKey({'ctrl'}, 'k', keyCode('up'))
remapKey({'ctrl'}, 'l', keyCode('right'))
remapKey({'ctrl', 'shift'}, 'h', keyCode('left', {'shift'}))
remapKey({'ctrl', 'shift'}, 'j', keyCode('down', {'shift'}))
remapKey({'ctrl', 'shift'}, 'k', keyCode('up', {'shift'}))
remapKey({'ctrl', 'shift'}, 'l', keyCode('right', {'shift'}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment