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
- 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
move by word
- u →
backward-word
- o →
forward-word
Try them. Try many times. Feel your finger muscles with the cursor movement.
move by paragraph
- h →
xah-beginning-of-line-or-block
- ; →
xah-end-of-line-or-block
Repeated call moves by paragraph.
move to begin / end of buffer
- Space h →
beginning-of-buffer
- Space n →
end-of-buffer
Text Editing
- e →
xah-backward-kill-word
- r →
xah-kill-word
- d →
xah-smart-delete
Delete something to the left. It may be 1 char, or whitespace, or bracketed text.
- g →
xah-delete-current-text-block
Delete the current text block.
- 5 →
delete-char
Delete 1 character to the right.
- w →
xah-shrink-whitespaces
Delete whitespaces. Repeated call delete more whitespaces.
- Space g →
kill-line
Delete to end of line.
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
Show Copy History
- Space v →
xah-show-kill-ring
Copy and Paste to Register
- 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〕
Mark and Text Selection
- t →
set-mark-command
Start selection. Move cursor to expand. Press again to unmark.
Text Selection Shortcuts
- 9 →
xah-select-text-in-quote
selects inner text between brackets or quotes (e.g. string) - 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.
There's no key to begin backward search. Just do isearch then press left arrow key.
💡 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.
(Emacs: Open Recently Opened File) Open recently opened/closed files:
- 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.
Emacs: Bookmark related for fast open files:
- 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 Buffer
3 → delete-other-windows
Unsplit all.
4 → split-window-below
Split top/bottom
, → xah-next-window-or-frame
Switch cursor to next pane or next window (emacs frame).
Space 3 → delete-window
remove current pane.
Space 4 → split-window-right
split left/right.
💡 TIP: on large monitor, avoid workflow with 1 fullscreen. 〔see Emacs: Fullscreen vs Multiple Windows〕
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 Brackets
when cursor is on a bracket,
8
(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 left of it, then press 5
(delete-char
)
.
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
- ALWAYS insert left/right brackets together.
- 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.
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
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.