Work more efficiently on your Mac (for developers)

Mike Solomon

Working faster

Software developers spend hour after hour on their machines, so it’s worth spending a little time improving common workflows now and then.

The time you can spend on this is virtually unbounded, but I have found there are a few tricks that many people miss—a handful of high-value improvements that can go a long way without hours of investment.

Some of these improvements require extra software, (all of it free and open source) and there’s a section at the bottom to set that up when needed.

1: Right-thumb control key

How often do you use the right-side command key? Never.

Instead of wasting that key, why not turn it into a control key? Control is very useful if you spend time in the terminal (iTerm2 is great) so you can do e.g. control+p to get the previous command, or control+r to search previous commands.

You press this key by curling your right thumb. It may feel unnatural at first, but before long the relief on your left pinky will be palpable.

Setup

First install the excellent Karabiner.

Command-R to Control-L configuration

Then open it and search for Command_R to Control_L and check the box. Done!

2: Faster key repeat

OS X defaults to a very slow key repeat rate, but it also doesn’t let you lower it enough to please me in System Preferences. This often comes in handy for moving short distances in text.

Setup

You can customize this in Karabiner’s GUI under “Key Repeat,”

Key repeat rate configuration

but if that seems to heavyweight you can instead run these commands in your terminal to copy my settings:

defaults write -g InitialKeyRepeat -int 10
defaults write -g KeyRepeat -int 1

3: A better shell with oh-my-zsh

Most people use Bash for their shell. Assuming you spend some time in the terminal, you probably already know your way around Bash pretty well. Sadly, Bash has limited capabilities, especially for command completion. Other shells, like Zsh, offer more but can be unfamiliar.

Enter oh-my-zsh: a layer of frosting on top of the powerful Z-shell that makes it Bash-compatible and adds a self-updating system of plugins and themes. You will find your autocomplete much improved as well as available niceties like changing directories by typing directory names without cd, and a very nice default prompt.

Oh-my-zsh also opens the door to more powerful customizations, and boasts an active community of people who have often already implemented features you wish your shell had.

Setup

First install Zsh. If you use Homebrew—which I hope you do—then simply brew install zsh. You will also need Git (brew install git). Then just run the curl-to-shell command from oh-my-zsh’s setup instructions, open up ~/.zshrc and enable a few plugins by adding them to the plugins=( ... ) array you’ll see in that file, and you’re done! Be sure to open a new terminal window to see your changes.

4: Syntax highlighting in the terminal

I love syntax highlighting because it lets me catch errors in my code as I type. Why not have the same thing for my bash commands in the terminal?

Terminal syntax highlighting screenshot

This syntax highlighting makes valid commands yellow, invalid commands red, highlights strings, and underlines valid file paths.

Setup

This one requires oh-my-zsh as seen in the previous tip. Syntax highlighting is an oh-my-zsh plugin, but it doesn’t come bundled by default.

Run the commands

mkdir ~/.oh-my-zsh/custom/plugins
git clone git://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting

to install the plugin. Then open up ~/.zshrc and add zsh-syntax-highlighting to the end of the plugins=( ... ) array. Open up a new terminal and enjoy your syntax highlighting!

5: File-searching aliases

Many terminal users set up aliases to shorten common tasks, such as alias gc='git commit' so that the whole command doesn’t need to be typed. You should of course set up custom aliases, but there are two in particular that I find useful quite often.

The first is f, which searches the current directory subtree for files with names containing a string (ignoring case). f png would find all PNG files in the current subtree, as well as “PNGisMyFavorite.txt” and so forth.

The second is r, which recursively greps the current directory subtree for files matching a pattern. r HTTP would grep for files containing that exact string, while r '"http[^"]*"' -i would search for double-quoted strings starting with “http”, ignoring case.

Setup

We will actually implement these as Bash (or Zsh) functions or aliases in ~/.bashrc or ~/.zshrc. Just add these lines anywhere in the file appropriate to your shell:

6: The “Hyper” key

You know what would be great? Having an extra modifier key open for whatever we want.

We can make use of Steve Losh’s idea of emulating the extra “Hyper” key introduced by the Space Cadet keyboard by defining Hyper as control+option+command+shift. Since no sane application will expect a user to hold all those keys at once, we can effectively create a new modifier key.

My primary use for Hyper is machine-global shortcut keys, especially for Slate.

Setup

I personally like to remap caps lock to Hyper, but some people already have that remapped. If you use caps lock for Escape, check out this tip.

Unfortunately, caps lock is treated specially in OS X and therefore requires two extra steps to remap.

First go to the System Preferences Keyboard pane and press the “Modifier Keys…” button and set Caps Lock to No Action.

Now install Seil, which only takes a second. Then change the caps lock key code to 80 (which is F19) as in the screenshot.

Caps lock configuration in Seil

The next step requires installing Karabiner, and is necessary whether or not caps lock is the key of choice.

After installation, open ~/Library/Application Support/Karabiner/private.xml (or open Karabiner and go to Misc & Uninstall > Open private.xml). Add this XML snippet directly under the <root> element. However, you may want to see my tip about Escape and use that snippet instead.

Save the file, then open Karabiner and press ReloadXML in the upper-right of the Change Key tab. Then search for Remap Caps and check the box.

Enabling the Hyper key via Karabiner

Now that that’s done, it’s time to set up some shortcuts that use Hyper in order to ease window management.

7: Managing windows with Slate

Slate is a window management application like Divvy or SizeUp. It lets you arrange, resize, switch between, and open applications and windows on one or more monitors.

By setting up a few basic commands in Slate, switching between and resizing windows in OS X becomes much faster. Some of my favorites are Hyper+spacebar to switch to Sublime Text, and Hyper+; to make the focused window resize and move to take the left half of the screen. I have a simple set of related commands that are easy to learn and use, but improve my daily efficiency manyfold.

Setup

First install Slate. Then open up ~/.slate and add this:

Then run Slate (or “Relaunch and Load Config” from the menu bar icon).

The configuration file is actually pretty easy to read. If you set up the Hyper key, then this file should just work for you, and I find these particular settings to be very useful.

8: Tap caps lock for Escape

If you’re already using caps lock for Hyper or Control or Escape or any other key, it is actually quite easy to overload it.

The key insight (which I stole from Steve Losh) is that these modifier keys are only used while held down in a key combination, which means we can assign additional functionality when tapped alone!

I recommend Hyper on hold and Escape on tap. This allows global key combinations for Slate and more, while also putting Vim mode switching (and also dialog dismissal) a quick tap away.

Setup

First set up the Hyper key, including Seil and Karabiner.

Now open ~/Library/Application Support/Karabiner/private.xml (or open Karabiner and go to Misc & Uninstall > Open private.xml). Add this XML snippet directly under the <root> element.

Save the file, then open Karabiner and press ReloadXML in the upper-right of the Change Key tab. Then search for Remap Caps and check the box.

Enabling the Hyper and Escape keys via Karabiner

Now go to the Parameters tab and change the Key Overlaid Modifier > Timeout to 300. This defines the boundary between what is interpreted as a hold and a what is interpreted as a tap.

Lowering the key overlaid modifier timeout

9: Tap shift to move over words

I find that moving my cursor word-by-word is very useful even outside my text editor. OS X provides line-editing shortcuts similar to Readline/Emacs, for example Control+a to jump to the beginning of a line and Control+e to jump to the end (which I recommend you use). Even better is to do this without a modifier key!

Inspired by a similar idea about parens from Steve Losh, we notice that tapping your shift key normally does nothing, and you rarely do so. Instead, why not tap left-shift to move one word to the left, and tap right-shift to move one word to the right?

I find this very useful for moving short distances in text of all kinds, and it soon becomes second nature.

Setup

First set up Karabiner.

Now open ~/Library/Application Support/Karabiner/private.xml (or open Karabiner and go to Misc & Uninstall > Open private.xml). Add this XML snippet directly under the <root> element.

Save the file, then open Karabiner and press ReloadXML in the upper-right of the Change Key tab. Then search for Tap shift and check the box.

Enabling the tap shift to move over words via Karabiner

Now go to the Key Repeat tab and change the Key Overlaid Modifier > Timeout to 300. This defines the boundary between what is interpreted as a hold and a what is interpreted as a tap.

Lowering the key overlaid modifier timeout

10: Ctrl+W deletes the previous word

When you make a typing mistake, it is often faster to rewrite the entire last word than to repeatedly press backspace to erase the typo. I find this to be much more efficient overall. Emacs users will already be familiar with the choice of Ctrl+W.

Setup

First set up Karabiner.

Open Karabiner and search for “Control+W”. Check the box next to “[ex] Control+W to Option+Delete” under “Emacs Mode”.

This works especially well with the right thumb control key.

Software

Some of these improvements require software. It’s all easy to set up, but I’ve provided links and a few words of advice.

Karabiner

Karabiner lets you rebind keys, key combinations, trackpad gestures, set key delays, and more.

It has a .dmg + wizard installer, and allows customization through a GUI and a private XML file, which lives at ~/Library/Application Support/Karabiner/private.xml

Seil

Seil lets you change low-level key codes and works well in conjuction with Karabiner. In particular, it lets you remap caps lock (something not possible with just Karabiner).

It has a .dmg + wizard installer and allows customization through a GUI.

Slate

Slate is a window management application like Divvy or SizeUp. It lets you arrange, resize, switch between, and open applications and windows on one or more monitors.

It can be installed with .dmg + drag-to-Applications or curl-to-shell methods. It can be customized through a ~/.slate config file, or through a powerful ~/.slate.js JavaScript config file.

More resources

I tried to hit high-value improvements that I don’t think most people already have, but there is a whole world of deeper customization out there. Here are some links to resources I’ve found useful:

comments powered by Disqus