Hammerspoon config inspired by Spacemacs
git clone https://github.com/agzam/spacehammer ~/.hammerspoon
I love Vim keybindings and I needed to find a better, more efficient way to manage windows and jump between the apps.
Ideally I wanted to stay in the home row and control as much as I can with h/j/k/l
keys. Adding tens (possibly hundreds) of key-combo shortcuts for every single desirable action is not a good solution.
Also, unlike in vanilla Vim - a single modal (to switch from Normal to Edit to Select mode) is often not enough. So I’ve taken approach inspired by Spacemacs. In Spacemacs - there is a single main modifier key - SPACE. Of course I couldn’t just use SPACE - because none of the modern operating systems can infer current mode of the operation - either user is typing or if cursor focused on an input field. So I have to use a key-combo.
Hammerspoon is incredibly powerful tool, and it has allowed me to take my workflow to a completely different level. Jumping between apps, controlling windows, searching things, etc. 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 just slows you down.
Main key combo is set to Cmd SPC
. By default, in OS X it’s used for something else (usually for Spotlight).
You’re gonna need to rebind that key combination!
Go to your Preferences/Keyboard, find associated keybinding and change it. Unfortunately, simply disabling it is NOT enough. You 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 that Cmd SPC
ain’t very convenient for you - simply modify ~/.hammerspoon/init.lua
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 windowu
- undo last window operation (similar to Spacemacs’sSPC w u
)
e
- Emacsg
- Chromei
- iTerms
- Slackb
- Brave
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 musicApp
in multimedia.lua
module
Cmd l
in Chrome 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
C-g
- Adding emoji to the last message -
C-r
(sorry, but defaultCmd-Shift+\
is horribly inconvenient) C-o/C-i
- jumping back and forth in history
j/k
- to scrolln/p
- page up/downCtrl-o/i
- to go to previous/next item
- [ ]
jk
orfd
to exit modals (likeevil-escape-key-sequence
in Emacs) - [ ] window configuration profiles (similar to Layouts feature in Spacemacs)
- [X]
Cmd SPC Tab
to switch to previous window This is now done, it’s bound toCMD+Spc+w
- similar to Spacemacs’sSPC w w
- [X] better module organization - so modals can be added without much hassle
- [ ] Disable non-available keys in a modal. Keys that not listed should be simply ignored see #1
- [ ] I’d like to find a way to jump to Chrome window with specific profile (right now
Ctrl-Cmd SPC a c
will switch to Chrome, but if you have multiple profiles you have to manually find the one you need) - [ ] 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
This is quite straightforward. Lua is extremely simple language. I shamelessly borrowed this state-machine implementation, and that makes adding new modes and extending current ones a piece of cake.
If you have any questions, please don’t hesitate to ask. If you feel uncomfortable about posting an issue - you can find me in Spacemacs’s Gitter channel, or on Clojurians Slack