Emacs: Xah Fly Keys Tutorial

By Xah Lee. Date: . Last updated: .

Here's a xah-fly-keys tutorial for beginners. I assume you have made no customization.

xah fly keys layout qwerty
xah-fly-keys command mode layout

Master Command/Insert Mode Switch

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

fxah-fly-insert-mode-activate to switch to insert mode.

or 【Space Spacexah-fly-insert-mode-activate to switch to insert mode.

Now try to switch between command mode and insert mode. Do them a few 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 hbeginning-of-buffer

Space nend-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 block is 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 previous kill-ring text.

To paste something twice, press v Ctrl+g v. or you can do v Return 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 a temp storage for some text, 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, "for example, string here". (xah-select-text-in-quote)

Space amark-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)

M-x

a to call a command by name.

or 【Space Enter】 (execute-extended-command)

Search

nisearch-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 yxah-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 rquery-replace

Space k rquery-replace-regexp

I recommend Emacs: xah-find.el, Find Replace in Pure Elisp 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, music 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

Use a workflow of 2 windows (emacs frame) side by side. Don't use workflow that have 1 fullscreen and rely on fixed split panes.

[see Programer Workflow Efficiency]

[see Emacs: Effective Windows Management]

switch buffer

Space fswitch-to-buffer

Space i d】 (ibuffer) list buffers.

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 C, JavaScript, especially lisp.

You don't need other packages for working brackets. If you code elisp, i also recommend Emacs: Xah Emacs Lisp 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 select 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. 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.

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


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.

back to Emacs: Xah Fly Keys

Patreon me $5 patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboard for Emacs

If you have a question, put $5 at patreon and message me.