Three tools to stay in the zone

So precious are those moments when we, software developers, find ourselves in the flow; yet exiting that state is way too easy. Today I will describe three tools you can use to stay in the zone, to boost your productivity and accomplish more.

Vimium (Chrome)

What: Mouse-free web surfing.

Why: We all google a lot. It goes like this: search something, scroll the page, click the url bar and refine the search, click on a result, go back, click on another result, etc. Moving our right hand to the mouse and back is simply distracting. Vimium solves the problem giving you shortcuts to navigate among pages, among tabs, and in the history. The ones I use the most are:

f: Shows a label on each link (e.g. AD), typing the label will jump to the
page.
: Hide the labels shown with f.
F: Same as f but open the page in a new tab.
H: Go back in history.
L: Go forward in history.

Check out all the commands typing ?. I combine Vimium shortcuts with the following Chrome shortcuts:

Cmd-1: Shows first tab.
Cmd-2: Shows second tab, similarly for other tabs.
Cmd-l: Select url so that you can trigger another search.

vimium f shortcut

Autojump

What: Smart cd command.

Why: I like building my project in the terminal, run script in the terminal, branch in the terminal. I use the terminal a lot. But jumping from one directory to another in a completely different place in the filesystem is a pain. Surely, most of you have probably already mastered:

pushd: Push current directory on the directory stack, change directory.
popd: Remove the top directory from the directory stack and change to it.
cd - : Change to previous directory (last cd).

All these commands are quick ways to move to places relative in time, but what if we need to go to a folder we haven’t been recently in? Autojump comes to rescue. Autojump keeps a database of the directories from where you usually run commands. Then, you can jump to a directory with a fuzzy match. Suppose I often run commands from ~/Desktop/Projects/Android/MyApp. Then I can jump to it by just running:

Autojump jumping in a folder

Hammerspoon (OS X)

What: Move windows around with the keyboard.

Why: Ever wanted to have two windows side by side, half of the screen each, and tried to use the mouse to do it? Luckily there is a better way. Meet Hammerspoon. Hammerspoon is an automation tool that binds the OS X API to Lua scripts. Basically, you can manipulate windows, the mouse pointer, file systems, etc. with Lua scripts. In practice, I use it to move windows around with my keyboard.

For example, you could assign the combination Alt-Cmd-left to resize the current window to the left half of the screen and Ctrl-Alt-Cmd-right to move the window to the monitor on the right. It also can do a function similar to f of Vimium but for OS X windows: it shows a label on each window (also the hidden ones) and you can focus it typing the letters on the label (see image below). Before Hammerspon I used Spectacle, but it lacks this labeling/hinting functionality. If you want to try it, a good place to start is from my init.lua configuration and tweak it for your needs.

Furthermore, here are some more OS X shortcuts for manipulating windows:

Cmd+tab: Cycle through apps windows.
Cmd+`: Cycle through windows of the same app.
Cmd+H: Hide window.
Cmd+M: Minimize window.
Cmd+tab, select app, Alt: Show a previous minimized window (Cmd+tab in this case does not work).

Hammerspoon labeling shortcut

These three are fundamental tools in my arsenal. I also use Alfred, an improved Spotlight with Google search, and Dash, a documentation tool so I don’t need to hit the network for some javadoc.