Skip to content

anshukla/spacehammer

 
 

Repository files navigation

Hammerspoon config inspired by Spacemacs

git clone https://github.com/anshukla/spacehammer.git -b develop ~/darnd/hammerspoon

Attention!

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.

Rationale

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.

Fennel

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

Prerequisites

Install Hammerspoon

You can use brew:

brew cask install hammerspoon

Install Fennel

brew install luarocks

luarocks install fennel

Important note!

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

For changing it in the system preferences

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.

For changing it in Spacehammer config

If you find Cmd+SPC to be inconvenient - modify relevant code in ~/.hammerspoon/core.fnl and set it to whatever keybinding you like.

Features

Cmd+SPC w - Window management

  • hjkl - moving windows around halves of the screen
  • Ctrl + hjkl - for jumping between application windows (handy for side by side windows)
  • w - jump to previous window
  • n/p - moving current window to prev/next monitor
  • Alt + hjkl - moving in increments (works across monitors)
  • Shift + hjkl - re-sizing active window
  • g - re-sizing with hs.grid
  • m - maximize active window
  • c - center active window
  • u - undo last window operation (similar to Spacemacs’s SPC w u)

Cmd+SPC a - Apps (quick jump)

  • e - Emacs
  • g - Chrome
  • i - iTerm
  • s - Slack

you can add more, also try Cmd SPC j j

Cmd+SPC SPC - open Alfred search bar

basically pressing SPC anytime in any modal takes you to Alfred search popup

Cmd+SPC m - multimedia controls

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

Other features

Alternative App Switcher Cmd n/p

Simple tab switcher for Chrome and iTerm Cmd j/k

Cmd l in Chrome is re-mapped to Cmd+Shift l

Simple vi-mode

  • Alt h/j/k/l - simple left/right/up/down
  • Alt+Shift h/j/k/l - word wise left/right/up/down
  • Alt+Ctrl+Shift h/j/k/l - selecting things

These can be disabled in certain apps (by default they they are ignored in Emacs)

Slack Desktop Client enhancements

  • 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 or C-e/C-y
  • Jumping to the end of the thread with Cmd-g
  • Adding emoji to the last message - Cmd-r (sorry, but default Cmd-Shift+\ is horribly inconvenient)
  • C-o/C-i - jumping back and forth in history

  • [ ] jk or fd to exit modals (like evil-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

Customizing

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!

About

Hammerspoon config inspired by Spacemacs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 78.2%
  • Emacs Lisp 21.8%