Emacs: Xah Fly Keys

By Xah Lee. Date: . Last updated: .

This is the home page of xah-fly-keys.

xah-fly-keys.el is a modal editing mode for emacs, like vi, but the design of key/command choice is based on command frequency statistics and ergonomics.

xah-fly-keys is more efficient than vim, or any keybinding set in history.

If you have hand pain from using emacs, you should consider using xah-fly-keys. One primary feature is you don't need to press Ctrl or ◆ Meta anymore.


Download at https://github.com/xahlee/xah-fly-keys

Also on MELPA http://melpa.org/#/xah-fly-keys 〔➤see Emacs: How to Install Packages Using ELPA, MELPA

Manual Install

Put the file xah-fly-keys.el in ~/.emacs.d/lisp/

put the following in your emacs init:

(add-to-list 'load-path "~/.emacs.d/lisp/")
(require 'xah-fly-keys)
(xah-fly-keys 1)

Key to Activate Command Mode

The command to activate command mode is xah-fly-command-mode-activate .

By default, it has the following keys:

Alt+Space】 or ↖ Home or 【F8】 or 【▤ Menu

When in command mode:

Key to Activate Insert Mode

While you are in command mode, 【u】 activates insertion mode. The command name is xah-fly-insert-mode-activate.

While you are in command mode, 【Space Space】 also activates insertion mode.

When in insert mode, keys insert characters.

Lead Key for Commands

You NEVER need to press 【Ctrl+x

Any emacs commands that has a keybinding starting with Ctrl+x, has also a key sequence binding in xah-fly-keys.

For example,

The first key in a key sequence we call it the “leader key”.

In the above examples, the Space is the leader key.

When in command mode, the 【Space】 is a leader key.

Globally, the leader key is the 【F9】 key.

For example, query-replace is 【Space p】, while in command mode, or 【F9 p】 always works.

Emac's M-x

When in command mode:

NEVER Need to Press Meta

Any emacs commands that has a Meta keybinding also has a keybinding without Meta in xah-fly-keys.

You never Need to Press Meta.

For example:

To find the key, call describe-key, then press the meta key combination. Emacs will print all its keybinding. You should be in command mode when doing this.

Standard Control Key Shortcuts

The following standard keys are supported by default.

It is not necessary to use these key shortcuts. These commands all have keys that does not need Ctrl.

The only ones you still need Ctrl key are:

dired mode single keys

In some modes, typing a letter key is a command. For example, in dired, 【m】 for mark, 【u】 for unmark.

When you are in insert mode, typing letter key will do whatever of that mode's commands.


Just open the file xah-fly-keys.el. Look at the code, it's really simple. If you prefer some other key or command, just change there.

Yes, i recommend you make a copy/fork, and just modify the copy, and use that version. This make lots things simpler. Don't worry about upgrade. I still make experimental changes almost every week. If, after a year, some keys have changed, you can stick to your own version, or chose to upgrade.

On a typical PC keyboard, i recommend you set left Alt or the Caps Lock key to send ↖ Home key signal for activating command mode.

How to Make the CapsLock Key Send Home Key Signal?

If you have a nice keyboard with extra thumb keys such as kinesis, ergodox, you can set a dedicated key to switch to insert mode.

;; make key 【end】 to activate insertion mode.
(global-set-key (kbd "<end>") 'xah-fly-insert-mode-activate)

You can set your own choice of a global leader key like this:

;; make Ctrl+space as the global leader key
(global-set-key (kbd "C-SPC") 'xah-fly-leader-key-map)

How does it compare to ergoemacs-mode?

ergoemacs-mode remaps the most frequencly used emacs commands to use 【Alt+key】, with key choice based on frequency of command call.

ergoemacs-mode also supports standard {Open 【Ctrl+o】, Close 【Ctrl+w】, New 【Ctrl+n】, …} keys familar to everyone. People who never use emacs can use it right away, without knowing any emacs keys.

ergoemacs-mode supports over 10 keyboard layouts, including: {QWERTY, Dvorak, Colemak, German, French, …}.

ergoemacs-mode is flexible. It provides many “themes”. You can pick your favorite keybinding set, or design your own.

ergoemacs-mode is part of FSF GNU Emacs, in ELPA repository.

If you don't like modal ways, I highly recommend ergoemacs-mode.

https://ergoemacs.github.io/ (ergoemacs-mode is lead by Matthew Fidler.)

How does it compare with evil-mode?

evil-mode lets you use vim keys in emacs. It has large user-base, mature, and with the advantage that you can also use vi/vim.


How long does it take to learn xah-fly-keys?

It'll take the same time when learning vi for the first time.

Probably about a month.

Optimal Configuration for Kinesis, Ergodox, Truly Ergonomic Keyboards

xah-fly-keys is designed for any keyboard. Special care has taken to make sure it works well for standard PC keyboard, Apple Keyboards ⌨, Laptop Keyboards, and in text terminal.

If you have a batman keyboard, much merrier. See:

xah-fly-keys Optimal Configuration for Kinesis, Ergodox, Truly Ergonomic Keyboards

Why I Created It

here's some detail about why i created it.

  1. I'm a QWERTY typer since ≈1987 on a typewriter.
  2. Switched to Dvorak in ≈1994.
  3. Started to use emacs in 1997.
  4. Live in emacs since 1998.
  5. Use emacs in text terminal only, and default GNU emacs keybinding, from 1997 to 2006.
  6. Started to experience RSI discomfort a few times since 2005, first time due to using laptop exclusively for 2 years.
〔➤see Summary of My Typing/RSI Experience 1992 – 2013

i always regarded the vi modal ways a hack of the hack of the unix lineage. 〔➤see History of Emacs & vi Keys〕 I'll never touch it. But starting in 2010, i had lots thoughts about keyboard efficiency, and it occurred to me the modal way is actually more efficient, for programers.

the reason is, that on average, ≈50% of key-strokes of programers are actually not data-entry (that is, 50% are actually {moving cursor, copy, cut, delete, indent, switch buffer, open/close, completion, …}.) 〔➤see Emacs's Command Frequency Statistics〕 That means, if using modal ways, 50% of the time you don't have to press key combinations to execute commands, just a single key for each command. So, the 50% of time when you call commands, each command you save about 1 key-stroke, so in total you save about 50% × 50% = 25% of key-strokes. The trade-off is that you have to constantly switch command/insert modes, which means adding a key stroke every time you do so. In the end, i estimate that modal keyset saves you about 10% of key strokes.

i've been wanting to create and experiment with vi modal ways since 2010. While there's viper-mode (which is a vi-emulator) and there's evil-mode (which is based on vim (a more advanced vi)), but their key/command choices is largely historical, not a clean design based on efficiency.

see also: on vi Keybinding vs Emacs Keybinding

Like it? Buy Xah Emacs Tutorial.

or, buy something from my keyboard store.