Emacs: Xah Fly Keys

By Xah Lee. Date: . Last updated: .

2017-01-21 NEW! now supports QWERTY layout!

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

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 ease-of-key score. Most frequently used commands have most easy keys.

If you have hand pain from using emacs, you should consider using xah-fly-keys. No 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-set-layout "qwerty") ; required if you use qwerty
;; (xah-fly-set-layout "dvorak") ; by default, it's dvorak

(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, the cursor shape is a black rectangle .

When in command mode:

xah fly keys layout qwerty
xah-fly-keys command mode layout. 〔qwerty, svg file 721×272〕 〔dvorak, svg file 721×272

Not many commands, but master these few will beat efficiency of vim.

To find the command name of a key, switch to command mode, then call describe-key, then press the key. (try it now, as you will do this frequently when learning.)

Some of these command have multiple purpsoses, dependinig on:

Just keep this in mind. You'll soon discover. Or, you can read their doc string.

Key to Activate Insert Mode

When you are in command mode, 【f】 (Dvorak 【u】) activates insertion mode. The command name is xah-fly-insert-mode-activate.

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

When in insert mode, keys insert characters. (or, whatever a letter key does in the current major more. For example, in dired, m marks a file.)

When in insert mode, the cursor shape is a i-beam .

Leader Key for Commands

Any emacs command that has a keybinding starting with Ctrl+x, has also a key sequence binding in xah-fly-keys, or a single key while in command mode.

You NEVER need to press 【Ctrl+x】.

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 r】 (Dvorak 【Space p】) while in command mode, but 【F9 r】 always works.

There are about 200 commands with leader key sequence. When learning xah-fly-keys, i recommend using which-key at https://github.com/justbur/emacs-which-key

With which-key on, when you press a leader key, subsequent keys and commands are displayed.

emacs which key mode
emacs which-key-mode.

Here's the most frequently used leader key commands and their key sequence. The leader key is indicated by a flag .

QWERTYDvorakcommand name
⌦ Deletesamexah-close-current-buffer
Enter ↵sameexecute-extended-command
QWERTYDvorakcommand name
3samedelete-window (unsplit panes)
QWERTYDvorakcommand name
a amark-whole-buffer (select all)
n bend-of-buffer
h dbeginning-of-buffer
y fxah-search-current-word
m mdired-jump
s oexchange-point-and-mark
r pquery-replace
k r t pquery-replace-regexp
; ssave-buffer
f uswitch-to-buffer

Most frequently used commands have 2-key sequence (counting leader key.) Other commands have a 3-key sequence. A few commands have 4 keys sequence, but these are basically used once a month or never.

Emac's M-x

When in command mode:

NEVER Need to Press Meta

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

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. (they can be disabled. See Emacs: Xah Fly Keys Customization)

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

The only ones you still need Ctrl key are:


When in command mode, 【n】 (Dvorak 【b】) starts isearch-forward.

When in isearch:

Dired Mode, Org 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.


Emacs: Xah Fly Keys Customization

Batman Keyboards

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

If you have a batman keyboard, much merrier.

Suggested optimal configuration: Kinesis/Ergodox layout for xah-fly-keys

Suggested optimal configuration: xah-fly-keys with Truly Ergonomic Keyboard

Frequently Asked Questions

How does it compare to ergoemacs-mode?

ergoemacs-mode remaps the most frequently 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 familiar 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.)

ergoemacs layout us
ergoemacs mode. Use Alt as the primary key for emacs commands.

How does it compare with evil-mode?

evil-mode lets you use vim keys in emacs. It has large user-base, and with the advantage that you can also use 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.

Why I Created It

See Emacs: Xah Fly Keys History

see also: on vi Keybinding vs Emacs Keybinding

Like it? Buy Xah Emacs Tutorial.

or, buy something from Best Keyboard for Emacs