Hammerspoon config inspired by Spacemacs
git clone https://github.com/anshukla/spacehammer.git -b develop ~/darnd/hammerspoon
Fennel 0.3.1 [2019-12-17] came up with some breaking changes that made master
branch no longer functional. Until the new version with lots of improvements and major redesign of the modal system is released, I suggest you use develop
branch of this project. Sorry for the inconvenience.
I love Vim and I love Vim keybindings, I use them wherever I can, and I needed to find a better, more efficient way to do my work in OSX.
Ideally, I wanted to stay in the home row and control as much as I could with only h/j/k/l
keys. Adding tens (possibly hundreds) of key-combo shortcuts for every single desirable action is not a right solution.
Also, unlike vanilla Vim - a single modal (to switch from Normal to Edit to Select mode) is often not enough. So I’ve taken an approach done in Spacemacs. In Spacemacs - there is a single primary modifier key - SPACE. Of course, I couldn’t just use SPACE - because none of the modern operating systems can infer the current mode of the operation - either you are typing or navigating, is cursor focused on an input field, etc.. So I had to use a key-combo. Default key-combo in Spacehammer is Cmd+SPC.
Hammerspoon is an incredibly powerful tool, and it allowed me to take my workflow to a completely different level. Jumping between apps, controlling windows, searching things, etc. have become so much easier - everything follows simple semantics of keeping your fingers on the home row. And no need to memorize myriad of keystrokes. Or to drag your hand to reach for mouse/touchpad/arrow keys - that inevitably slows you down.
Spacehammer initially was written in Lua (as the majority of Hammerspoon configs), but later I have discovered Fennel - tiny Lisp that compiles into Lua. I decided to re-write it in Fennel. There is nothing wrong with Lua - I simply prefer Lisp - it is compact, has zero overhead and makes me more productive. Lua and Fennel can live together in the same config, I still have non-critical parts that I have not yet re-written in Fennel. Also - if you are interested (now outdated) version of Spacehammer lives in lua branch
You can use brew:
brew cask install hammerspoon
brew install luarocks
luarocks install fennel
Main key combo is set to Cmd+SPC
. By default, in OS X it’s used for something else (usually for Spotlight).
In order for it to work - you either will have to rebind it in your system or choose a different key-combo and change it in the config
Go to your Preferences/Keyboard, find associated keybinding and change it. Unfortunately, simply disabling it isn’t enough. You’d have to set it to be something else e.g. Ctrl+Cmd+Shift+\
or whatever (I dunno - use your imagination), it doesn’t really matter, since you can then uncheck the checkbox.
If you find Cmd+SPC
to be inconvenient - modify relevant code in ~/.hammerspoon/core.fnl
and set it to whatever keybinding you like.
hjkl
- moving windows around halves of the screenCtrl + hjkl
- for jumping between application windows (handy for side by side windows)w
- jump to previous windown/p
- moving current window to prev/next monitorAlt + hjkl
- moving in increments (works across monitors)Shift + hjkl
- re-sizing active windowg
- re-sizing with hs.gridm
- maximize active windowc
- center active windowu
- undo last window operation (similar to Spacemacs’sSPC w u
)
e
- Emacsg
- Chromei
- iTerms
- Slack
you can add more, also try Cmd SPC j j
basically pressing SPC
anytime in any modal takes you to Alfred search popup
Why just not use media-keys?
a) because different external keyboards impose their own ways to control media.
b) I’d like to keep fingers on the home row
it’s configured to work with Google Play Music Desktop App. If you want it to be Spotify or anything else - change the value of music-app
in multimedia.fnl
module
Cmd l
in Chrome is re-mapped to Cmd+Shift l
Alt h/j/k/l
- simple left/right/up/downAlt+Shift h/j/k/l
- word wise left/right/up/downAlt+Ctrl+Shift h/j/k/l
- selecting things
These can be disabled in certain apps (by default they they are ignored in Emacs)
- Switching to Slack via “Apps” modal
CMD+SPC a s
- automatically opens Slack’s “Jump to” dialog - Scrolling current Slack thread with
C-j/C-k
orC-e/C-y
- Jumping to the end of the thread with
Cmd-g
- Adding emoji to the last message -
Cmd-r
(sorry, but defaultCmd-Shift+\
is horribly inconvenient) C-o/C-i
- jumping back and forth in history
- [ ]
jk
orfd
to exit modals (likeevil-escape-key-sequence
in Emacs) - [ ] window configuration profiles (similar to Layouts feature in Spacemacs)
- [ ] Disable non-available keys in a modal. Keys that not listed should be simply ignored see #1
- [ ] Another thing I want is to be able to toggle ChromeDevtools panel - this is somewhat tricky, see this issue
- [ ] Better than default HUD display (something less obtrusive than
hs.alert
would be nice
That is pretty straightforward. Both, Fennel and Lua are extremely simple languages. I shamelessly borrowed this state-machine implementation (why write from scratch?). Adding new modals, or app specific keys and app specific modals is quite simple, reach out if you have any questions. Thanks!