Emacs key bindings everywhere

I used to use Emacs for everything, and I loved it. You could do absolutely everything really efficiently from the keyboard using a number of arcane key combinations, and once the learning curve had been overcome you could absolutely fly through your work.

Now I use Visual Studio for my coding work, MS Word for documentation, and NotePad++ for everything else, I find myself wishing that I didn’t have to move positions on the keyboard to move the cursor, delete characters and words, and do basic document navigation. I know VS.NET has Emacs key bindings available, but I find that their incompleteness means I have to mentally figure out whether to use Windows or Emacs shortcuts. This is especially difficult when switching between applications.

So I decided to whip up a quick AutoHotKey script that reproduces the basic Emacs document navigation key bindings, sticking to the shortcuts that don’t interfere too much with standard Windows shortcuts (for example, I left Ctrl-V alone :)). You can toggle “Emacs Mode” on and off using the CapsLock key, and because it uses AutoHotKey to translate key strokes, it works everywhere your keyboard does :). I’ve been using it for months and found it quite useful, so I thought I’d put it online before I lose it. :)

You can download the script from here [ZIP]. You’ll also need AutoHotKey. I’m far from an expert on AutoHotKey, so feel free to comment or email if you find any problems with the script.

Key bindings

The keys mapped by the script are described below. The mappings aren’t perfect, they simply translate Emacs keys into similar Windows key combinations. Because different applications implement concepts like “next word” differently, sometimes you get results that are slightly different to expected. C is Control, M is meta key (Alt).

CapsLockToggle Emacs mode on/off
C-pPrevious line (move up)
C-nNext line (move down)
C-fForward one character (move right) Note: conflicts with normal "find" shortcut
C-bBack one character (move left) Note: conflicts with normal "bold" shortcut
M-fForward one word
M-bBack one word
C-aStart of line Note: conflicts with normal "Select all" shortcut
C-eEnd of line
C-<Start of page
C->End of page
C-_Undo
C-dDelete character after cursor
M-dDelete word after cursor
M-DelDelete word before cursor
C-kKill line
C-wCut region
M-wCopy region
C-yPaste (no kill ring, so don’t get full Emacs yank ability)

If you want to use regular CapsLock functionality, try holding down Shift while pressing CapsLock. For me at least, this lets me toggle CapsLock on and off without being caught by the script.

Comments