map jj to Esc globally on mac

So, I like vim and use the key mapping jj for Esc.

Is there some way to on a global level in Mac OS X map jj to Esc?

I've tried Better Touch Tool where I can have global key mappings but they don't support mapping of multiple keys (e.g. jj) but just mappings of like ctrl+j.

PS. The motivation:

In Light Table there's a Vim-plugin. However, because of a short coming of CodeMirror you can't add key mappings with multiple keys (e.g. jj). (https://github.com/LightTable/LightTable/issues/923)


I also like vim! I was looking for something very similar (I use jk but some difference).

I figured it out!

TL;DR You want to use the Karabiner app

It's a little bit confusing at first but they have tons of options for remapping keys. The one you're looking for is going to involve "simultaneous keys" fortunately there's a search so if you search for "simultaneous" and "escape" you'll find a couple that map to escape:

Karabiner Screenshot

You'll notice that this doesn't quite fit either of our use cases though...you're looking for jj and I'm looking for jk. If you're content retraining your muscle memory to ji then you're already done. If you'd still like to stick with jj though, you're going to have to do a few extra steps.

Fortunately, it's relatively simple to add your own custom remappings as xml files. Your installation of Karabiner should come with a private.xml that lives in /Users/Username/Library/Application Support/Karabiner (should be able to find it quickly with spotlight). That file starts out pretty bare so that you can fill it up with whatever sort of new mappings you want. You can check out the documentation on doing so here.

For what you want you just wanna replace what's there with the following:

<?xml version="1.0"?>
<root>
    <item>
        <name>Stephen Custom Keyboard mappings</name>
        <appendix></appendix>

        <item>
            <name>SimultaneousKeyPresses</name>
            <item>
                <name>J and K to escape</name>
                <appendix>(J+K to Escape)</appendix>
                <identifier>private.j_k_to_escape</identifier>
                <autogen>__SimultaneousKeyPresses__ KeyCode::J, KeyCode::K, KeyCode::ESCAPE</autogen>
            </item>
        </item>
    </item>
</root>