Skip to content

gcentauri/xah-fly-keys-layer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xah-fly-keys layer

img/xah-logo.png

Table of Contents

Description

This layer adds an alternative modal editing mode for Emacs.

“like vi, but the design of key/command choice is based on command frequency statistics and ease-of-key score. Most frequently used commands have most easy keys.”

xah-fly-keys has been developed over years of experience by Xah Lee, a long time contributer to the Emacs community.

Gain the modal superpowers of the dark side, without succumbing to evil!

Features:

  • You NEVER need to press 【Ctrl+x】or Meta! Use a leader key instead!
  • There are about 200 commands with leader key sequences.
  • Efficient keys for common navigation and editing tasks in command mode.
  • The key bindings are based on experience and observed frequency of use.

Install

Clone this repository into .emacs.d/private/xah-fly-keys, or where ever you keep your private layers:

git clone https://github.com/gcentauri/xah-fly-keys-layer.git ~/.emacs.d/private/xah-fly-keys

Note - the directory the layer files are in must be named xah-fly-keys.

To use this configuration layer, add it to your ~/.spacemacs. You will need to add xah-fly-keys to the existing dotspacemacs-configuration-layers list in this file. You should have the dotspacemacs-editing-style set to 'emacs.

It is recommended to change some of the defaults in your .spacemacs file, in order to avoid some unwanted cross-over with some key bindings.

  • set the dotspacemacs-leader-key to an empty string, as having it set to SPC interferes with the which-key mappings.
  • set dotspacemacs-colorize-cursor-according-to-state nil so that the cursor will reflect the xah-fly-keys state instead.

Configuration

Keyboard layout

This layer assumes a qwerty layout and uses that by default. You can configure xah-fly-keys to use other keyboard layouts with the xah-fly-keys-layout variable.

The possible values are:

  • azerty, azerty-be
  • colemak, colemak-mod-dh
  • dvorak, programer-dvorak
  • qwerty, qwerty-abnt
  • qwertz
  • workman

For example, to use the dvorak layout, add the following to your layers list:

(xah-fly-keys :variables xah-fly-keys-layout "dvorak")

Cursor appearance for command and insert modes

You can customize the appearance of the cursor using two variables:

  • xah-fly-keys-command-mode-cursor
  • xah-fly-keys-insert-mode-cursor

Both variables are a pair of the form (COLOR . CURSOR-TYPE). COLOR is a string, either one of the defined color words in the list-colors-display or a hex code for the color. The CURSOR-TYPE is one of the types that can be set on the cursor-type variable:

t               use the cursor specified for the frame
nil             don’t display a cursor
box             display a filled box cursor
hollow          display a hollow box cursor
bar             display a vertical bar cursor with default width
(bar . WIDTH)   display a vertical bar cursor with width WIDTH
hbar            display a horizontal bar cursor with default height
(hbar . HEIGHT) display a horizontal bar cursor with height HEIGHT
ANYTHING ELSE   display a hollow box cursor

For example,

(xah-fly-keys :variables
              xah-fly-keys-command-mode-cursor '("yellow" . box)
              xah-fly-keys-insert-mode-cursor '("#ff00ff" . hbar))

It defaults to very distinctive, contrasting cursors to help indicate state. 😄

Preferred incremental search function

This will default to either helm-swoop or swiper if helm/ivy layer is used. Otherwise it will be isearch-foward. You can set it to your preferred command.

(xah-fly-keys :variables xah-fly-keys-search-function 'helm-swoop)

Preferred M-x function

This defaults to the standard execute-extended-command, which seems to be remapped by helm or ivy if those layers are installed. Set this variable if you prefer another M-x command or need to configure it explicitly.

(xah-fly-keys :variables xah-fly-keys-M-x-function 'counsel-M-x)

Swap the leader keys

If you’d like to have the Spacemacs leader key on the space bar rather than the xah-fly-keys menu, then it’s possible to swap them.

I tried implementing this with a config variable, but it doesn’t quite work as expected. Until that is sorted out, add this to your dotspacemacs/user-config to swap the leader keys for Spacemacs and xah-fly-keys.

(defun xah-fly-keys-swap-spacemacs-leader ()
      (progn
        (define-key xah-fly-key-map (kbd "SPC") 'spacemacs-cmds)
        (define-key xah-fly-key-map (kbd "M-m") 'xah-fly-leader-key-map)))

(add-hook 'xah-fly-command-mode-activate-hook 'xah-fly-keys-swap-spacemacs-leader)

You’ll also need to set the dotspacemacs-emacs-leader key to an empty string. It appears that sometimes the which-key menu will be affected by this change.

Key bindings

See xah-fly-keys for the modal keymap defined by Xah Lee.

Command mode

Key bindingDescription
M-mspacemacs commands keymap
ESCxah-fly-leader-key-map
SPCxah-fly-leader-key-map
'xah-cycle-hyphen-underscore-space
,xah-next-window-or-frame
-xah-backward-punct
.xah-forward-right-bracket
/xah-goto-matching-bracket
0xah-pop-local-mark-ring
1xah-extend-selection
2xah-select-line
3delete-other-windows
4split-window-below
5delete-char
6xah-select-block
7xah-select-line
8xah-extend-selection
9xah-select-text-in-quote
;xah-end-of-line-or-block
=xah-forward-punct
[hippie-expand
`other-frame
asmex
bxah-toggle-letter-case
cxah-copy-line-or-region
dxah-delete-backward-char-or-bracket-text
ebackward-kill-word
fxah-fly-insert-mode-activate
gxah-delete-current-text-block
hxah-beginning-of-line-or-block
iprevious-line
jbackward-char
knext-line
lforward-char
mxah-backward-left-bracket
nisearch-forward
oforward-word
pxah-insert–space-before
qxah-reformat-lines
rxah-kill-word
sopen-line
tset-mark-command
ubackward-word
vxah-paste-or-paste-previous
wxah-shrink-whitespaces
xxah-cut-line-or-region
yundo
zxah-comment-dwim
DELxah-fly-leader-key-map
<C-f11>xah-previous-emacs-buffer
<C-f12>xah-next-emacs-buffer
<f11>xah-~previous-user-buffer
<f12>xah-next-user-buffer
<f8>xah-fly-command-mode-activate-no-hook
<f9>xah-fly-leader-key-map
<home>xah-fly-command-mode-activate
<menu>xah-fly-command-mode-activate

Leader Key Map

Key BindingDescription
SPC TABxah-fly–tab-key-map
SPC RETexecute-extended-command
SPC SPCxah-fly-insert-mode-activate
SPC 'xah-show-form-feed-as-line
SPC ,xah-fly-w-keymap
SPC 3delete-window
SPC 4split-window-right
SPC 5balance-windows
SPC 6xah-upcase-sentence
SPC 9ispell-word
SPC ;save-buffer
SPC \toggle-input-method
SPC amark-whole-buffer
SPC bxah-toggle-previous-letter-case
SPC cxah-copy-all-or-region
SPC dxah-fly-e-keymap
SPC exah-fly-dot-keymap
SPC fswitch-to-buffer
SPC gkill-line
SPC hbeginning-of-buffer
SPC ixah-fly-c-keymap
SPC jxah-fly-h-keymap
SPC kxah-fly-t-keymap
SPC lxah-fly-n-keymap
SPC mdired-jump
SPC nend-of-buffer
SPC oxah-fly-r-keymap
SPC precenter-top-bottom
SPC qxah-fill-or-unfill
SPC rquery-replace
SPC sexchange-point-and-mark
SPC txah-show-kill-ring
SPC uisearch-forward
SPC vxah-paste-or-paste-previous
SPC wxah-fly-comma-keymap
SPC xxah-cut-all-or-region
SPC yxah-search-current-word
SPC DELxah-fly-insert-mode-activate

Sub keymaps

You’ll notice that there are several sub keymaps after pressing a leader key. These are organized by ease of use, and should really be categorized by finger and keyboard row. I’ve listed some of the functionality for each of the keymaps, but use which-key and you’ll discover more details.

  • 【SPC ,】 - Eval, kill emacs
  • 【SPC k】 - registers, replace, occur
  • 【SPC o】 - rectangles, macros, number registers
  • 【SPC l】 - modes, view, windows
  • 【SPC j】 - help, apropos, info
  • 【SPC d】 - inserting chars, brackets, unicode
  • 【SPC i】 - files, bookmarks, external apps
  • 【SPC w】 - xref, find identifiers
  • 【SPC e】 - search, highlight, fonts
  • 【SPC TAB】 - indent, expand, abbrev

About

Spacemacs configuration layer for the xah-fly-keys package

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published