Emacs: Xah Fly Keys
Major News
- 2023-09-22 starting Emacs 29 (Released 2023-07) only version.
- 2023-03-18 now Escape by default activates command mode, but only when emacs runs in GUI mode. [see Emacs: Xah Fly Keys Design, Binding Escape Key]
- 2022-10-25 to 2022-10-26 More major internal change. No user visible change.
xah-fly--key-char
is now gone. Replaced byxah-fly--convert-kbd-str
. Explicitly named keymaps e.g.xah-fly-Rp2p1-key-map
orxah-fly-c-key-map
are gone. Now their keymap is just part ofxah-fly-leader-key-map
. Much simpler. - 2022-10-22 major internal change. Variable xah-fly-layouts holds a list of layouts. Function
xah-fly-keys-set-layout
no longer support M-x customize. Reason: supporting it makes the code much more complex. - 2022-09-11 major change and fix for colemak dh layouts, now accurate names: colemak-dhm, colemak-dhm-angle, colemak-dhk
- 2022-06-11 Xah Fly Keys now on nonGnu ELPA. lots other code updates in past year.
- 2021-06-23 added 3 more keys to neo2 layout. by sieman, pull request #122
- 2021-06-23 added bepo layout, by brabalan. pull request #121.
- 2021-05-19 added layouts • carpalx-qgmlwy • carpalx-qgmlwb • carpalx-qfmlwy. Thanks to uwusual
- 2021-02-21 now supports pt-nativo layout (for Portuguese). Thanks to xavierpinho. [see Portuguese Ergonomic Keyboard Layout: pt-Nativo]
- 2021-02-09 now supports ergo layouts for germany: neo2, koy, adnw. Thanks to VitruvianVice.
- 2020-07-12 the old version of xah fly keys before the key engine change on 2020-04-27 is now at xah-fly-keys_old_2020-04-18.el
- 2020-04-27 Major engine rewrite, by Dan Langlois and Will Dey (wi11dey). Big thank you. Now, xah fly keys has priority, won't have the very annoying problem in modes like magit and org. In next few days am going to update the customization page. Vast majority of code will work as is. If you have problem, goto xahlee discord, or file a bug report.
What is Xah Fly Keys
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, consider using Xah Fly Keys. Never need to press Ctrl+x and never need to press Meta anymore.

Video Intro to Xah Fly Keys
Download
Archived Old Versions
Install from NonGNU ELPA
Alt+x package-install
RET xah-fly-keys
RET
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) ;; specify a layout (xah-fly-keys-set-layout "qwerty") ;; possible values ;; adnw , azerty , azerty-be , bepo , carpalx-qfmlwy , carpalx-qgmlwb , carpalx-qgmlwy , colemak , colemak-dhm , colemak-dhm-angle , colemak-dhk , dvorak , koy , neo2 , norman , programer-dvorak , pt-nativo , qwerty , qwerty-abnt , qwerty-no (qwerty Norwegian) , qwertz , workman (xah-fly-keys 1)
What Does Command Mode Do?
When in command mode:
- Right hand letter keys are moving cursor, in general. For example, i j k l , are arrows.
- Left hand letter keys are deleting/modifying text.
- Alt+x
xah-fly-command-mode-activate
【Alt+Space】 - Activates command mode.
By default, it has the following keys:
Alt+Space or Home or F8 or Escape (only works in GUI emacs, not in terminal) or ▤ Menu (the menu key is the key on Microsoft keyboards, usually besides right Ctrl)
When in command mode, the cursor shape is a black rectangle ▮ (Does not work in some text terminal), and the first character in emacs status bar (aka mode line) displays lowercase c.

Insert Mode
When in insert mode, keys insert characters. (or, whatever a letter key does in the current major mode. For example, in dired , m marks a file.)
- Alt+x
xah-fly-insert-mode-activate
- Activate insert mode.
When in command mode, f activates insertion mode.
When in command mode, Space Space also activates insertion mode.
When in insert mode, the cursor shape is a I-beam ⌶ (does not work in some text terminal) and the first character in emacs status bar (aka mode line) displays i.

Leader Key Sequence for Commands
You NEVER need to press Ctrl+x. For example,
- Ctrl+x b (
switch-to-buffer
) is Space f - Ctrl+x Ctrl+f (
find-file
) is Space i e - Ctrl+x 1 (
delete-other-windows
) is 3 while in command mode.
The first key in a key sequence we call it the “leader key”. For example, the Space is the leader key in Space f.
When in command mode, the Space is a leader key.
Here's example of frequently used ones.
- Space Space →
xah-fly-insert-mode-activate
- Space Enter →
execute-extended-command
- Space f →
switch-to-buffer
- Space h →
beginning-of-buffer
- Space n →
end-of-buffer
- Space r →
query-replace
- Space k r →
query-replace-regexp
There are about 200 commands with leader key sequence. Most frequently used commands have 2 keys (counting the leader key). Other commands have 3 keys. Some rarely used have 4.
List All Leader Key Sequence
To list all leader key sequence and their commands, switch to command mode, then press Space Ctrl+h

Emacs M-x
When in command mode:
- a →
execute-extended-command
. - Space Return →
execute-extended-command
.
NEVER Need to Press Meta
Any emacs command that has a Meta (Alt) keybinding also have a keybinding without Meta in Xah Fly Keys.
For example:
- Alt+f (
forward-word
) is o while in command mode. - Alt+% (
query-replace
) is Space r while in command mode.
If you are familiar with a emacs key, such as
Alt+f,
to find the new key in xah fly keys,
Alt+x describe-key
, then press the meta key combination you know. Emacs will print the key of xah fly keys if it is on.
Standard Control Key Shortcuts
The following standard keys are supported by default. (they can be disabled.)
- Ctrl+Tab →
xah-next-user-buffer
- Ctrl+Shift+Tab →
xah-previous-user-buffer
- Ctrl+v → Paste.
yank
- Ctrl+w →
xah-close-current-buffer
- Ctrl+z →
undo
- Ctrl+n →
xah-new-empty-buffer
- Ctrl+o → open.
find-file
- Ctrl+s →
save-buffer
- Ctrl+Shift+s → Save As.
write-file
- Ctrl+Shift+t →
xah-open-last-closed
- Ctrl++ → zoom-in.
text-scale-increase
- Ctrl+- → zoom-out.
text-scale-decrease
It is not necessary to use these key shortcuts. These commands all have keys that do not need Ctrl.
The only time you need to press Ctrl key are:
- Ctrl+c for major mode commands.
- Ctrl+g for canceling command or key.
- Ctrl+q for
quoted-insert
. - Ctrl+h for help.
isearch
When in command mode, n starts isearch-forward
.
When in isearch:
- Ctrl+y → paste.
- ← → → search backward/forward.
- ↑ ↓ → previous/next search history.
- Return → exit isearch and leave cursor at the current location.
- Ctrl+g exit isearch and leave cursor at original location.
Dired Mode, Org Mode, Single Keys
In plain GNU Emacs, in some modes, typing a letter key does not insert letter, but runs a special command. For example, in dired, m for mark, u for unmark.
With Xah Fly Keys, when in insert mode, typing letter key will do whatever of that mode's commands.
Tutorial
Customization
Batman Keyboards
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 is part of FSF GNU Emacs, in ELPA repository. (but you should probably download the version from MELPA, because it's usually more up-to-date.)
If you don't like modal ways, I 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 number of users, and with the advantage that you'll be fluent in both emacs and vim.
https://github.com/emacs-evil/evil
How long does it take to learn Xah Fly Keys?
It'll take the same amount of time if learning vi for the first time.
If you practice one hour per day, about a month to be fluent.
Does Xah Fly Keys work in terminal?
YES. Extra effort went to make sure, it works in text terminal, and 100%.
How to setup Xah Fly Keys in doom emacs
2023-01-29 info here may be outdated.
Download Xah Fly Keys, and place it at
~/.emacs.d/.local/straight/repos/xah-fly-keys/xah-fly-keys.el
in the file
.doom.d/init.el
,
comment this out:
(evil +everywhere)
in the file
.doom.d/config.el
,
add the following
(change it suitably):
(require 'xah-fly-keys) (xah-fly-keys-set-layout "qwerty") (xah-fly-keys 1) (setq doom-leader-key "<f1>")
Are the keys hard to remember?
History
See also: on vi Keybinding vs Emacs Keybinding