Emacs: Xah Fly Keys Tutorial

By Xah Lee. Date: . Last updated: .

Here's Xah Fly Keys tutorial for beginners. I assume you have made no customization.

1 2 3 4 5 6 7 8 9 0 a b c d e f g h i j k l m n o p q r s t u v w x y z , . ' \ / = - [ ] ; ` Xah Fly Keys command mode layout other-frame unsplit split Select¶ S Line S w S (▮) M-x ⌫() insert ⌦|¶ ←|¶ →|¶ ⌦w format ⌫␣ ⌫w mark undo →w ←w Case search paste cut copy cmt ←( →) →() next◫ leader key Cmd Mode

Pick a layout above. All keybinding shortcuts on this page changes accordingly.

Master Command/Insert Mode Switch

Alt + Space xah-fly-command-mode-activate-no-hook to switch to command mode.

f xah-fly-insert-mode-activate to switch to insert mode.

or Space Space xah-fly-insert-mode-activate to switch to insert mode.

Now try to switch between command mode and insert mode. Do them 5 times.

In this tutorial, you should try the keys multiple times.

Cursor Movement

Switch to command mode. Then,

i j k l keys are arrows.

u o are moving by word.

Try them. Try many times. Feel your finger muscles with the cursor movement.

h ; move to beginning/end of line/indent/paragraph. (try holding it down)

Space h beginning-of-buffer

Space n end-of-buffer

Text Editing

e r to delete word left/right. (xah-backward-kill-word) (xah-kill-word)

d to delete 1 char to the left. (xah-delete-backward-char-or-bracket-text)

If the character is a bracket character (any of ()[]{}), the whole bracketed text will be deleted, including the bracket. To delete just the brackets, press Ctrl + u first. To delete single bracket without pair, move cursor to the left of it, then press 5.

g to delete the current text block. (text blocks are separated by empty lines.) (xah-delete-current-text-block)

5 (delete-char). Delete 1 character to the right.

w (xah-shrink-whitespaces) for deleting blank lines or white spaces. Try holding it down.

Space g (kill-line) delete to end of line.

undo

y to undo.

Ctrl + g y to redo. To redo again, just press y 1 or more times. To reverse direction, press Ctrl + g again.

I recommend not to use any undo/redo package. If you have them installed (e.g. undo tree), uninstall it.

Cut Copy Paste

x (xah-cut-line-or-region) to cut. It'll cut current line. Try holding the key.

c (xah-copy-line-or-region) Try holding the key.

v (xah-paste-or-paste-previous) When pressed twice, it'll paste the previous copied text (kill-ring). Repeat to swap to earlier copied text.

To paste something twice, press v Ctrl + g v. or you can do v Return v or v Space v.

To paste something 5 times, Ctrl + u 5 v.

More:

Space c (xah-copy-all-or-region)

Space x (xah-cut-all-or-region)

Space t (xah-show-kill-ring) Show copy history. Useful when you want text that you copied long ago. Just move cursor there and copy the part you want.

Sometimes you want to copy something and use it for the next 10 minutes while editing, use:

Text Selection

These are quick selections. 90% of the time, they are all you need.

6 selects text block. Try holding the key down. (xah-select-block)

7 selects line. Try holding the key down. (xah-select-line)

8 select current word. If cursor is before a bracket, select the bracket and inner text. The command name is xah-extend-selection, but currently best used for just selecting word or bracket text.

9 selects inner text between brackets or quotes, e.g. "inside ▮string". (xah-select-text-in-quote)

Space a mark-whole-buffer

To cancel selection, press Ctrl + g

Mark

For more complex selection, use mark.

t (set-mark-command) to mark. Then, move cursor will create selection. Press again to unmark.

Space s (exchange-point-and-mark) This is sometimes useful. It puts cursor to the other side of selection.

0 move cursor to previous marked position in current buffer. (xah-pop-local-mark-ring) Try pressing it a few times.

Ctrl + d move cursor to previous marked position, of all buffers. (pop-global-mark)

execute-extended-command (M-x)

a to call a command by name.

or Space Enter (execute-extended-command)

iSearch

n isearch-forward. Use this to move cursor too. (You don't need other packages to jump to locations.) [see Emacs: avy ace-jump vs isearch]

Space y xah-search-current-word or selection.

When in isearch:

There's no key to begin backward search. Just do isearch then press left arrow key.

Find Replace

Space r query-replace

Space k r query-replace-regexp

I recommend Emacs: Find Replace in Pure Elisp, xah-find.el for find replace in a directory.

Open Close Save

You can use the following standard keys for now.

When you are comfortable with Xah Fly Keys, and feel like you want to reduce using Control, then learn the following.

Open Files

Space i f (xah-open-file-at-cursor)

Space i g (xah-copy-file-path)

Space m go to dired and place cursor on file name. (dired-jump)

Open in external apps (for image, pdf, vidio/audio files, etc.):

Bookmark related for fast open files:

Open recently opened/closed files:

Press Space i Ctrl + h to see a full list.

You don't need any extra packages to efficiently open files.

You should never need to type file path to open file, unless it's a new file you rarely work with.

All files or directories you work daily, should be bookmarked, or with open recent.

Split Buffer

3 unsplit all. (delete-other-windows)

4 split top/bottom (split-window-below)

, Switch cursor to next pane, and if no split pane, switch to next window if any. (xah-next-window-or-frame)

Space 3 remove current pane. (delete-window)

Space 4 split left/right. split-window-right

If you are on desktop with large monitor, do use a workflow of 2 windows (emacs frame) side by side. Avoid workflow with 1 fullscreen.

[see Programer Workflow Efficiency]

[see Emacs Workflow: Fullscreen vs Multiple Frames]

switch buffer

Working with Quote and Brackets

xah-fly-keys has a system to work with brackets. Brackets includes ()[]{}“” and all Unicode brackets.

These allows you to work efficiently in any programing language with lots brackets, such as Java, JavaScript, especially lisp.

You don't need other packages for working with brackets. If you code emacs lisp, i also recommend Emacs: Xah Elisp Mode

Move to Brackets

m . move to left/right bracket. (xah-backward-left-bracket) (xah-forward-right-bracket)

/ (xah-goto-matching-bracket). When cursor is on a bracket, jump to the matching one. If cursor is not on a bracket, move it to parent left bracket.

Select Brackets

when cursor is on a bracket, 8 selects the whole. (xah-extend-selection)

Delete Brackets

d to delete 1 char to the left. (xah-delete-backward-char-or-bracket-text) If the character is a bracket character (any of ()[]{}), the whole bracketed text will be deleted, including the bracket.

Ctrl + u d → delete bracket on the left of cursor, and its matching pair.

To delete single bracket without pair, move cursor to the left of it, then press 5.

Change Brackets

Alt + x xah-change-bracket-pairs

Insert Brackets

ALWAYS insert left/right brackets together.

Turn on electric-pair-mode on

(electric-pair-mode 1)

Alternatively,

Space d k insert parenthesis pair. (xah-insert-paren)

Space d l (xah-insert-square-bracket)

Space d j (xah-insert-brace)

Space d u (xah-insert-ascii-double-quote)

Space d i (xah-insert-ascii-single-quote)

Now, type Space d Ctrl + h to see all other brackets and quotes you can insert.

Font Size

List All Leader Keys

Space Ctrl + h → list all leader key sequences and commands. (if you have which-key-mode installed, you must turn it off first.)

More Advanced

ok, the above are the basics.

Now, there are about 200 commands with leader keys. These basically replace what emacs C-x does.

You might want to learn them as you go.

When in command mode, press Space Ctrl + h to list all leader key sequence commands.

Remember to use Alt + x describe-function and Alt + x describe-key to find what's the key or command name.

Misc Notes

Command Mode Key Must be Most Easy Key

It's critically important that the key to switch to command mode must be the most easy key on your keyboard.

I suggest the CapsLock on typical PC keyboards or laptop keyboards.

For how, see Emacs: Xah Fly Keys Customization

Insert Mode is Same as Default GNU Emacs Key

When in insert mode, it acts like Xah Fly Keys is off. (except a handful of global keys with Ctrl or Meta, but you can turn them off in customization.)

In some emacs modes such as dired , typing a letter will run some special command. For example, in dired, m for mark, u for unmark.

So, whenever you think there is some problem, do switch to insert mode.

Xah Fly Keys