Emacs: Xah Fly Keys Tutorial
Here's Xah Fly Keys tutorial for beginners. I assume you have made no customization.
Pick a Layout
All keybinding shortcuts on this page changes accordingly.
Activate Command Mode, Insert Mode
- Alt+Space (
xah-fly-command-mode-activate
) - Esc (in GUI emacs) (
xah-fly-command-mode-activate
)
- f or Space Space (
xah-fly-insert-mode-activate
)
Exit Emacs
- Space , x (
save-buffers-kill-terminal
)
Cursor Movement
Move by char
i j k l
Try them. Try many times. Feel your finger muscles with the cursor movement.
Move by word
- u (
backward-word
) - o (
forward-word
)
Move by paragraph
- h (
xah-beginning-of-line-or-block
) - ; (
xah-end-of-line-or-block
)
Repeated call moves by paragraph.
Move to beginning of buffer
- Space h (
beginning-of-buffer
) - Space n (
end-of-buffer
)
Text Editing
- e (
backward-kill-word
) - r (
kill-word
)
- d (
xah-smart-delete
) → Cut something to the left. If left is whitespaces, cut them all. If it is any bracket, cut the brackets and its innertext. Else, delete 1 char.
- w (
xah-shrink-whitespaces
) → Delete spaces or blank lines. Repeated call deletes the other type.
- Space g g (
kill-line
) → cut line from cursor to end. - Space g h (
xah-delete-current-text-block
) → cut current text block.
undo
- y (
undo
)
To redo, do an undo, then press key to switch to command mode (or Ctrl+g), then do undo. To reverse direction, press Ctrl+g again.
💡 TIP: I recommend not to use any external undo/redo package.
Cut Copy Paste
- x (
xah-cut-line-or-region
) → Repeated call cut more lines. - c (
xah-copy-line-or-region
) → Repeated call copy more lines. - v (
xah-paste-or-paste-previous
) → Repeated call paste previous.
To paste something twice, call paste, then enter space or return or switch command mode, then paste again.
To paste something 5 times,
Space . (universal-argument
) 5, then call paste.
Cut All, Copy All
- Space x (
xah-cut-all-or-region
) - Space c (
xah-copy-all-or-region
)
Mark and Text Selection
- g (
xah-extend-selection
) → Start selection. By default, select current word, or bracketed text, or whitespaces, or other, depending on what's under cursor. Move cursor to expand.
- Space g Space (
set-mark-command
) → start selection but don't select anything.
- t (
xah-fly-cancel
) → cancel selection.
- Space g , (
exchange-point-and-mark
) → Move cursor the the other end of selection.
- Space g k (
xah-select-text-in-quote
)
Select All
- Space a (
mark-whole-buffer
) → Select all.
Call Command by Name (M-x)
- a (
execute-extended-command
) - Space Return (
execute-extended-command
)
Search Text
- n (
isearch-forward
) → Start isearch - Space y (
xah-search-current-word
) → Search current word or selection.
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.
💡 TIP: i recommend not installing external packages to jump cursor to locations.
Find Replace
- Space r (
query-replace
) - Space k r (
query-replace-regexp
)
New Open Close Save
You can use the following standard keys.
- Ctrl+n (
xah-new-empty-buffer
) - Ctrl+o (
find-file
) → Open. - Ctrl+w (
xah-close-current-buffer
) - Ctrl+s (
save-buffer
) - Ctrl+Shift+s (
write-file
) → Save as. - Ctrl+Shift+t (
xah-open-last-closed
) → Open last closed
When you are comfortable with Xah Fly Keys, and do not want to use Control key, then use the following.
- Space i l (
xah-new-empty-buffer
) - Space i e (
find-file
) - Space u (
xah-close-current-buffer
) - Space ; (
save-buffer
) - Space i ; (
write-file
) - Space i r (
xah-open-last-closed
)
Open Files
- Space i e (
find-file
) → Open file. - Space i f (
xah-open-file-at-cursor
) → Open URL or file path. - Space i c (
xah-copy-file-path
) - Space m (
dired-jump
) → Go to dired and place cursor on file name.
Open Recently Opened File, Recently Closed File
Emacs: Open Recently Opened File
- Space i j (
recentf-open-files
) → List recently opened files. - Space i r (
xah-open-last-closed
) - Space i y (
xah-open-recently-closed
) → List recently closed files.
Bookmark
- Space i p (
bookmark-set
) → Add current file to bookmark. - Space i i (
bookmark-bmenu-list
) → List bookmarks - Space i o (
bookmark-jump
) → Open a file in bookmark.
Switch Buffer
- Space f (
switch-to-buffer
) - Space i d (
ibuffer
) → List buffers.
-
Ctrl+8 or Ctrl+Tab (
xah-next-user-buffer
) -
Ctrl+7
or
Ctrl+Shift+Tab (
xah-previous-user-buffer
) -
Ctrl+6 (
xah-next-emacs-buffer
) -
Ctrl+5 (
xah-previous-emacs-buffer
)
Split Window
- - (
split-window-below
) → Split to bottom. - = (
split-window-right
) → Split to right. - ' (
delete-other-windows
) → Unsplit all.
Switch Window
- , (
xah-next-window-or-frame
) → Switch cursor to next pane or next window (emacs frame).
Working with Quote and Brackets
xah-fly-keys has a system to work with brackets.
Brackets includes
()[]{}“”
and all
Unicode: Brackets, Quotes 「」【】《》
Move to Brackets
- m (
xah-backward-left-bracket
) → Move to left bracket. - . (
xah-forward-right-bracket
) → Move to 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 Bracket Text
when cursor is on a bracket,
H (xah-extend-selection
) selects the whole.
Delete Whole Bracketed Text
d (xah-smart-delete
) → When the left char is a bracket, delete the bracketed text. The deleted text is automatically copied.
Delete Bracket Pair
move cursor to the right of a bracket, then
Space . (universal-argument
)
d (xah-smart-delete
)
Delete a Single Bracket
move cursor to the right of it, then press E.
Insert Brackets
- Space d k (
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 s (
xah-insert-ascii-single-quote
)
- These commands insert bracket pairs.
- When cursor is at beginning of line, they put brackets around the line.
- When there is a text selection, they put brackets around it.
Now, type Space d Ctrl+h to see all other brackets and quotes you can insert.
💡 TIP: Always insert bracket pairs together.
Change Brackets
- Space r h (
xah-change-bracket-pairs
)
Font Size
- Ctrl+= (
text-scale-increase
) - Ctrl+- (
text-scale-decrease
)
- Space l a (
text-scale-adjust
)
List All Leader Keys
More Advanced
- Space t (
xah-show-kill-ring
) → Show copy history
- T (
xah-select-text-in-quote
) → Selects inner text between brackets or quotes (e.g. string)
- Space k c (
copy-to-register
) → Copy selection to a register. - Space k v (
insert-register
) → Paste from a register.
〔see Emacs: Copy to Register〕
More Leader Keys
There are about 200 commands with leader key prefix. They basically replace what emacs C-x does.
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.