Skip to content

Instantly share code, notes, and snippets.

Created September 30, 2016 00:36
Show Gist options
  • Save prenagha/1c28f71cb4d52b3133a4bff1b3849c3e to your computer and use it in GitHub Desktop.
Save prenagha/1c28f71cb4d52b3133a4bff1b3849c3e to your computer and use it in GitHub Desktop.
Hammerspoon Config File, Hyper Key, Karabiner-Elements
-- hattip
-- hattip
-- A global variable for the sub-key Hyper Mode
k ={}, 'F18')
-- Hyper+key for all the below are setup somewhere
-- The handler already exists, usually in Keyboard Maestro
-- we just have to get the right keystroke sent
hyperBindings = {'c','m','a','r','d','g','s','f','TAB','v','b'}
for i,key in ipairs(hyperBindings) do
k:bind({}, key, nil, function() hs.eventtap.keyStroke({'cmd','alt','shift','ctrl'}, key)
k.triggered = true
-- Enter Hyper Mode when F19 (left control) is pressed
pressedF19 = function()
k.triggered = false
-- Leave Hyper Mode when F19 (left control) is pressed,
-- send ESCAPE if no other keys are pressed.
releasedF19 = function()
if not k.triggered then
hs.eventtap.keyStroke({}, 'ESCAPE')
-- Bind the Hyper key
f19 = hs.hotkey.bind({}, 'F19', pressedF19, releasedF19)
-- vi cursor movement commands
movements = {
{ 'h', {}, 'LEFT'},
{ 'j', {}, 'DOWN'},
{ 'k', {}, 'UP'},
{ 'l', {}, 'RIGHT'},
{ '0', {'cmd'}, 'LEFT'}, -- beginning of line
{ '4', {'cmd'}, 'RIGHT'}, -- end of line
{ 'b', {'alt'}, 'LEFT'}, -- back word
{ 'w', {'alt'}, 'RIGHT'}, -- forward word
for i,bnd in ipairs(movements) do
hs.hotkey.bind({'ctrl'}, bnd[1], function()
-- Reload config when any lua file in config directory changes
function reloadConfig(files)
doReload = false
for _,file in pairs(files) do
if file:sub(-4) == '.lua' then
doReload = true
if doReload then
local myWatcher ='HOME') .. '/.hammerspoon/', reloadConfig):start()'Config loaded')
Copy link

ssaadh commented Oct 3, 2016

Thanks for this. Liked seeing a bit of different config here. Get me grokking Hammerspoon and even Lua a bit more.

Copy link

Awesome. My muscle memory is thanking you! But isn't there a way to use hjkl with the hyper key instead of control? And this way you have to release ctrl+j after each stroke which is a bit tedious.

Copy link

Thank you for your work on this! I forked and uploaded my tweaked code for my own setup here:

Gave attribution but not sure of the correct etiquette, so let me know if anything should be revised.

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