Emacs: Xah Fly Keys Customization

By Xah Lee. Date: . Last updated: .

This page shows how to customize Emacs: Xah Fly Keys šŸ“¦.

Add Keys to Command Mode Keymap

;; put this AFTER loading Xah Fly Keys
(define-key xah-fly-command-map (kbd "x") 'myCommand)

Add Keys in Insert Mode Keymap

;; put this AFTER loading Xah Fly Keys
(define-key xah-fly-insert-map (kbd "x") 'myCommand)

Disable Change to Emacs Control Keybinding

By default, Xah Fly Keys support standard ones like copy cut paste open, etc. When disabled, no control binding is changed by Xah Fly Keys.

(setq xah-fly-use-control-key nil)

Disable Changes to Emacs Meta Keybinding

By default, Xah Fly Keys disables most of emacs meta keybinding, and add 2 or so.

You can disable this by:

(setq xah-fly-use-meta-key nil)

Xah Fly Keys Hooks

There are these hooks you can use:

xah-fly-command-mode-activate-hook
Hook variable. Value should be a list of function Symbols. When command mode is activated, these functions are called after activation.
xah-fly-insert-mode-activate-hook
Hook variable. Value should be a list of function Symbols. When insert mode is activated, these functions are called after activation.

What Keyspots Are Available for Personal Keybinding?

You can bind keys to any of the spots for personal commands.

You can create a whole leader key map sequence for all your personal keys. For example, start with

Remapping: Make Major Mode Use Xah Fly Keys Command Mode Key

For example, to make the ā€œi j k lā€ keys scroll a PDF Tools page while in command mode:

(with-eval-after-load 'pdf-view
  (define-key pdf-view-mode-map [remap next-line] 'pdf-view-next-line-or-next-page)
  (define-key pdf-view-mode-map [remap previous-line] 'pdf-view-previous-line-or-previous-page))

To add a remapping, find the command that Xah Fly Keys binds to a key in command mode (e.g. through describe-key), then add a binding in the major/minor mode's map like this:

(define-key major-or-minor-mode-map [remap xah-fly-command-name] 'mode-specific-command-name)

2024-03-03 Note: the above is originally written by Will Dey in 2020-04 when he did a major rewrite of Xah Fly Keys key engine. Thanks to Will Dey.

Final Words

I recommend that you do not change much keys in Xah Fly Keys. Just stick to it. Because, one thing about creating a keybinding system is that there's a lot habit to overcome. I've been changing keys every month from about 2008 to 2017. Each time, it's extremely painful, and with strong desire to go back. And, once you start to explore keys, you often become biased towards your CURRENT workflow or work. So, you get into a situation that you change every few months, when project changes, or your choice of major mode changes, and in particular, when you got a new keyboard.

Also, if you don't have a year or two dedicated study about keybinding system, you create a key system that you think must be logically flawless, but actually just to your habit, your current keyboard, and your workflow, but to someone using a different keyboard and different coding task, workflow, it may not be good.

xah-fly-keys's keybinding choices is not scientifically the best, because that is basically an illusive concept, but is near optimal.

If you are interested in keybinding efficiency research, be sure to read:

emacs, Xah Fly Keys, customization