Emacs: Xah Fly Keys
2017-09-21 NEW! now supports QWERTZ layout! (used in Germany and central Europe.)
2017-07-27 NEW! now supports Workman layout!
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. Never need to press Ctrl+x and never need to press Meta anymore.
Download
Download at https://github.com/xahlee/xah-fly-keys
Also on MELPA http://melpa.org/#/xah-fly-keys
Melpa Install
[see Emacs: How to Install Packages Using ELPA, MELPA]
After you installed from MELPA, put the following in your init:
(require 'xah-fly-keys) (xah-fly-keys-set-layout "qwerty") ; required if you use qwerty ;; (xah-fly-keys-set-layout "workman") ; required if you use workman ;; (xah-fly-set-layout "dvorak") ; by default, it's dvorak (xah-fly-keys 1)
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-keys-set-layout "workman") ; required if you use workman ;; (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 ▮ (won't work in some text terminal).
- When in command mode, the first character in emacs status bar (aka mode line) displays capital C.
When in command mode:
- right hand letter keys are moving cursor, in general. For example, I J K L, are arrows. (On Dvorak, it's C H T N)
- left hand letter keys are deleting/modifying text.
Only 36 commands, but master these few will already beat the efficiency of vim.
To find the command name of a key, switch to command mode, then Alt+x describe-key
【Ctrl+h k】, then press the key. (try it now, as you will do this frequently when learning.)
Some of these command have multiple purpsoses, dependinig on:
- position of cursor.
- if repeated.
- current selection positions.
Just keep this in mind. You'll soon discover when you use them. Or, you can read their doc string shown by
describe-key.
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 ⌶. (won't work in some text terminal)
- When in insert mode, the first character in emacs status bar (aka mode line) displays capital I.
Leader Key for Commands
You NEVER need to press 【Ctrl+x】.
For example,
- 【Ctrl+x b】 (
switch-to-buffer) is 【Space f】 (Dvorak 【Space u】) - 【Ctrl+x Ctrl+f】 (
find-file) is 【Space i e】 (Dvorak 【Space c .】) - 【Ctrl+x n n】 (
narrow-to-region) is 【Space l l】 (Dvorak 【Space n n】) - 【Ctrl+x o】 (
delete-other-windows) is 3 while in command mode.
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.
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.
Here's the most frequently used leader key commands and their key sequence. The leader key is indicated by leader.
| QWERTY | Dvorak | command name |
|---|---|---|
| 【leader Space】 | same | xah-fly-insert-mode-activate |
| 【leader Enter】 | same | execute-extended-command |
| QWERTY | Dvorak | command name |
|---|---|---|
| 【leader f】 | 【leader u】 | switch-to-buffer |
| 【leader a】 | 【leader a】 | mark-whole-buffer (select all) |
| 【leader h】 | 【leader d】 | beginning-of-buffer |
| 【leader n】 | 【leader b】 | end-of-buffer |
| 【leader r】 | 【leader p】 | query-replace |
| 【leader k r】 | 【leader t p】 | query-replace-regexp |
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:
- 【a】 →
execute-extended-command. - 【Space Return】 →
execute-extended-command.
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:
- 【Alt+f】 (
forward-word) is 【o】 (Dvorak 【r】) while in command mode. - 【Alt+%】 (
query-replace) is 【Space r】 (Dvorak 【Space p】) while in command mode.
To find the key, Alt+x 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)
- 【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 - 【Ctrl+0】 → default text size.
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 cancel.
- 【Ctrl+q】 for
quoted-insert. - 【Ctrl+h】 for help.
isearch
When in command mode, 【n】 (Dvorak 【b】) starts isearch-forward.
When in isearch:
- left/right arrow keys ← → do search backward/forward.
- up/down arrow keys ↑ ↓ do previous/next search item.
- Return exits isearch and leave cursor at the current location.
- Ctrl+g exits isearch and leave cursor at original location.
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.
Customization
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.)
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 able to use both emacs and 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 to be fluent.
Does xah-fly-keys work in terminal?
YES
Why I Created It
See Emacs: Xah Fly Keys History
see also: on vi Keybinding vs Emacs Keybinding
Xah-Fly-Keys Testimonial