Skip to content

Instantly share code, notes, and snippets.

@cicloid
Created September 28, 2016 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cicloid/5ff16f21c447b503bf1b6dc60367e98b to your computer and use it in GitHub Desktop.
Save cicloid/5ff16f21c447b503bf1b6dc60367e98b to your computer and use it in GitHub Desktop.
Universal ViM mode using hammerspoon
-- Modal ViM
local function keyCode(key)
return function() hs.eventtap.keyStroke({}, key) end
end
hs.hotkey.bind({"cmd", "alt"}, 'h', keyCode('left') , nil, keyCode('left'))
hs.hotkey.bind({"cmd", "alt"}, 'j', keyCode('down') , nil, keyCode('down') )
hs.hotkey.bind({"cmd", "alt"}, 'k', keyCode('up') , nil, keyCode('up') )
hs.hotkey.bind({"cmd", "alt"}, 'l', keyCode('right'), nil, keyCode('right') )
modalVimMode = hs.hotkey.modal.new({"cmd", "alt"}, '\\', "Vimificating")
modalVimMode:bind({}, 'h', keyCode('left') , nil, keyCode('left') )
modalVimMode:bind({}, 'j', keyCode('down') , nil, keyCode('down') )
modalVimMode:bind({}, 'k', keyCode('up') , nil, keyCode('up') )
modalVimMode:bind({}, 'l', keyCode('right'), nil, keyCode('right') )
function modalVimMode:exited()
-- hs.screen.primaryScreen():setGamma({alpha=1.0,red=0.0,green=0.0,blue=0.0},{blue=1.0,green=1.0,red=1.0})
hs.alert.show("No ViM mode")
end
modalVimMode:bind({}, 'escape', function() modalVimMode:exit() end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment