KHD, KWM and more

March 31, 2017

It’s been a while, and much has happened. I stumbled upon many great things that redefine the way I interact with macOS as a power user. Especially relevant to my past posts though, are neovim with dein, a refined iTerm 2 (previously I used a patched version to achieve a borderless version with increased padding), khd and kwm, and finally Übersicht (which is German, and translates to overview).

Me writing this post with neovim and kwm

This post however, is solely dedicated to kwm and khd. kwm is a tiling window manager, and khd is a hotkey manager, to which I’ll come in a second. Tiling window management is a totally different concept to what we normally do on macOS. We click on windows and drag them around, order them like we want, and completely rely on the mouse for interactions (except for cmd + TAB that is). As we all know, using the mouse is inefficient. Especially when it comes to ordering windows. That’s why windows started to come with hot corners, which allow you to drag a window to the very right of the screen to have it occupy the right half of your screen. You drag it to the center top to let the dragged window occupy the screen completely. You geht the idea. Similar tools have been around on macOS for a long time. I started using Moon and others, and lately found Magnet. These tools are normally quite limited in their capabilities and response time with such tools is never the best.

Now kwm therefore is kind of a supercharged snapping tool. You can think of kwm as a program running on your mac that waits for commands that you can give with kwmc, or, well, khd. khd is a tool made from the developer of kwm that allows the binding of these kwmc commands to actual hotkeys. khd seems to have two modes, the prefix mode, and the … modes mode I guess (see here). The modes mode seems to behave like vim, which I like. The prefix mode reminds me of emacs. So for both religions you have a compatible mode of operation. How awesome is that?


In order to start using khd and kwm simply install them with brew.

brew install koekeishiya/formulae/kwm


brew install koekeishiya/formulae/khd

To get started we’ll use the default configurations for both:

cp /usr/local/opt/khd/khdrc ~/.khdrc
mkdir -p ~/.kwm
cp /usr/local/opt/kwm/kwmrc ~/.kwm/kwmrc

The kwmrc configures things like the border color for focused windows, the blacklisting of apps that shouldn’t be tiled but floated instead. The comments in the config file will help you a lot with getting started. I am currently using an unchanged version of it, but will personalize it in the future. As for the khd config, this is where the magic happens. Here it is defined how you interact with kwm. The default runs khd in the prefix mode, which I think of as emacs mode. You enter the prefix, which by the default configuration is ctrl + s, and you then enter what you want khd to do, quickly. At least for all the hotkeys listed with prefix +. There are some that use ctrl + alt + something or such, which can be used just like any hotkey, you press them all at once.

So now you have kwm and khd running. After you finally found out how to use the prefix mode, you can start getting faster with organizing your windows properly without any mouse movement involved. 🎉 If you don’t use fish that is. If you do, read on.

How does this work anyway?

After I set it all up, I was lost. I had a terminal open with the .khdrc to help me navigate this new land of awesomeness. But I couldn’t really use the prefix stuff and the responsiveness of this setup was overall disappointing. After some googling around, I found this issue though. It seemed that fish does, what fish always seems to do, it breaks things, because no one takes care of fish compatibility. TL;DR: you have to edit the launch agent, the little helper thingy that keeps care of opening apps when you log in.

The important part are the lines 12 to 17.

The file can be found under ~/Library/LaunchAgents/homebrew.mxcl.kwm.plist. After making the changes log out and in again. You now should have a snappy khd/ kwm. How cool is that? You can finally use the prefix hotkeys and your commands get executed in an acceptable response time.

And now what?

I haven’t had the time to fiddle around with this setup much. I’m quite busy right now, so I stick with the default config for now. I probably will check out the modes mode. But for now this setup improves the way I did things before tremendously.

The features I like the most are:

  • mouse focus follow: the window where the mouse is over gets the focuse. I loved this about pekwm back in my linux days.
  • give focus to screen: with one hotkey you can move your mouse to the center of a screen. For someone with a dual monitor setup this is saving a lot of mouse movement!
  • automatic tiling of windows
  • send windows to spaces, screens and positions on the screen

If these sound like something that your work can benefit from, then I definitely recommend you give kwm enough. If it seems to much to configure and something bugs you about it, you could also have a look at Amethyst, another tiling manager for macOS.

As for the rest that I mentioned, that will hopefully be another post. I have to update my dotfiles on github anyway. But before I can do that, I have to fix some issues with my new desired color scheme for neovim and fish. So stay tuned for more!

comments powered by Disqus