1 use package with xah-fly-keys

1
2
3
4
5
6
7
8
9
(use-package! xah-fly-keys
  :init
  (require 'xah-fly-keys)
  ;;disable xah-fly-shared-map
  (define-key xah-fly-shared-map (kbd "C-n") nil)
  (define-key xah-fly-shared-map (kbd "C-a") nil)
  :config
  (xah-fly-keys 1)
  ;; FIXEME: end line with under headlines

2 define-key xah-fly-keys-map(Command mode)

2.1 Index Owner Customization keys

[2020-10-13 Tue 16:47] <- r-keymap -> regex

2.2 xah-fly-key-map

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
:bind
(:map xah-fly-key-map
 ("ESC" . nil)
 ("DEL" . nil)

 ("a" . counsel-M-x)
 ("b" . backward-word)
 ("c" . xah-copy-line-or-region)
 ("d" . xah-end-of-line-or-block)
 ("e" . xah-beginning-of-line-or-block)
 ("f" . xah-fly-insert-mode-activate)

 ("g" . backward-word)
 ("h" . forward-word)

 ("s" . gtrun-s-keymap)
 ("i" . previous-line)
 ("j" . forward-char)
 ("k" . next-line)
 ("l" . backward-char)
 ("m" . isearch-backward)
 ("n" . isearch-forward)

 ("o" . xah-delete-current-text-block)
 ("p" . xah-fly-p-keymap)
 ("q" . quit-window)
 ("r" . gtrun-r-keymap)
 ("t" . set-mark-command)

 ("u" . undo-fu-only-redo)
 ("v" . xah-paste-or-paste-previous)
 ("w" . ace-window)
 ("x" . xah-cut-line-or-region)
 ("y" . undo-fu-only-undo)
 ("z" . xah-goto-matching-bracket)



 ("[" . xah-backward-punct)
 ("]" . xah-forward-punct)


 ("1" . xah-extend-selection)
 ("2" . xah-select-line)
 ("3" . delete-other-windows)
 ("4" . split-window-below)
 ("5" . delete-char)
 ("6" . xah-select-block)
 ("7" . xah-select-line)
 ("8" . xah-extend-selection)
 ("9" . xah-select-text-in-quote)
 ("0" . xah-pop-local-mark-ring)

 ("C-s" . swiper-isearch)
 ("C-c i" . counsel-imenu)
 ("C-v" . scrollkeeper-contents-up)
 ("C-x c" . xah-fly-command-mode-activate)
 )

3 specific keys in different mode map

3.1 load all of specific keys

1
2
3
:config
(define-key xah-fly-key-map (kbd ".") 'gtrun-xah-fly-keys-dot) (define-key xah-fly-key-map (kbd "s-p") 'gtrun-xah-fly-keys-P) (define-key xah-fly-key-map (kbd "-") 'gtrun-xah-fly-keys-minus) (define-key xah-fly-key-map (kbd "/") 'gtrun-xah-fly-keys-slash) (define-key xah-fly-key-map (kbd ",") 'gtrun-xah-fly-keys-comma) (define-key xah-fly-key-map (kbd ";") 'gtrun-xah-fly-keys-semicolon)
(define-key xah-fly-key-map (kbd "'") 'gtrun-xah-fly-keys-apostrophe)

3.2 Only Linux keys

1
2
3
4
5
6
7
8
9
(when (eq system-type 'gnu/linux)
  (when (display-graphic-p)
  (define-key xah-fly-key-map (kbd "r") 'eaf-open)
  (define-key xah-fly-key-map (kbd "w") 'snails)
  ))

(when (display-graphic-p)
 (define-key key-translation-map (kbd "ESC") (kbd "C-x c"))
)

3.3 .-dot

1
2
3
4
5
6
7
8
(defun gtrun-xah-fly-keys-dot ()
  "key `.'"
  (interactive)
  (cond
   ((eq major-mode 'org-mode) (call-interactively 'org-edit-src-code))
   ((eq major-mode 'org-tanglesync-mode) (call-interactively 'org-edit-src-code))
   ((eq major-mode 'elfeed-search-mode) (call-interactively 'scrollkeeper-contents-up))
   (t nil)))

3.4 ,-comma

1
2
3
4
5
6
7
8
9
(defun gtrun-xah-fly-keys-comma ()
  "key `,'"
  (interactive)
  (cond
   ;; ((eq major-mode 'dired-mode) (call-interactively 'd))
   ((eq major-mode 'w3m-mode) (call-interactively 'scrollkeeper-contents-down))
   ((eq major-mode 'elfeed-show-mode) (call-interactively 'scrollkeeper-contents-down))
   ((eq major-mode 'elfeed-search-mode) (call-interactively 'scrollkeeper-contents-down))
   (t nil)))

3.5 /-slash

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
(defun gtrun-xah-fly-keys-slash ()
  "key `/'"
  (interactive)
  (cond
   ;; ((eq major-mode 'dired-mode) (call-interactively 'd))
   ((eq major-mode 'dired-mode) (call-interactively 'vinegar/dired-diff))
   ((eq major-mode 'w3m-mode) (call-interactively 'w3m-bookmark-add-current-url))
   ((eq major-mode 'org-agenda-mode) (call-interactively 'org-agenda-filter-by-tag))
   ((eq major-mode 'org-mode) (call-interactively 'helm-org-agenda-files-headings))
   ((eq major-mode 'elfeed-search-mode) (call-interactively 'elfeed-update))
   ((eq major-mode 'ess-julia-mode) (call-interactively 'julia-mode))
   (t nil)))

3.6 ;-semicolon

1
2
3
4
5
6
7
(defun gtrun-xah-fly-keys-semicolon ()
  "key `;'"
  (interactive)
  (cond
   ((eq major-mode 'org-mode) (call-interactively 'sl-store-link))

   (t nil)))

3.7 ‘-apostrophe

1
2
3
4
5
6
7
(defun gtrun-xah-fly-keys-apostrophe ()
  "key `''"
  (interactive)
  (cond
   ((eq major-mode 'org-mode) (call-interactively 'sl-insert-link))

   (t nil)))

3.8 =-e

1
2
3
4
5
6
7
(defun gtrun-xah-equality-fly-keys ()
  "key `='"
  (interactive)
  (cond
   ;; ((eq major-mode 'dired-mode) (call-interactively 'd))
   (t nil)))

3.9 p-keymap

[2020-09-23 Wed 03:14] <- define-key xah-fly-keys-map(Command mode)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
(xah-fly--define-keys
 (define-prefix-command 'xah-fly-p-keymap)
 '(
   ("," . xah-open-in-external-app)
   ("." . find-file)
   ("c" . bookmark-bmenu-list)
   ("e" . ibuffer)
   ("u" . xah-open-file-at-cursor)
   ("h" . recentf-open-files)
   ("i" . xah-copy-file-path)
   ("l" . bookmark-set)
   ("n" . xah-new-empty-buffer)
   ("o" . xah-show-in-desktop)
   ("p" . xah-open-last-closed)
   ("f" . xah-open-recently-closed)
   ("y" . xah-list-recently-closed)
   ("r" . xah-open-file-fast)
   ("s" . write-file)
   ))

3.10 s-keymap

[2020-10-13 Tue 17:00] <- Index Owner Customization keys

1
2
3
4
5
6
(xah-fly--define-keys
 (define-prefix-command 'gtrun-s-keymap)
 '(
   ("a" . mark-whole-buffer)
   ("s" . save-buffer)
   ))

3.11 r-keymap -> regex

[2020-10-13 Tue 18:21] <- Index Owner Customization keys

[2020-10-13 Tue 16:47] -> Index Owner Customization keys

1
2
3
4
5
(xah-fly--define-keys
 (define-prefix-command 'gtrun-r-keymap)
 '(
   ("r" . color-rg-search-input)
   ))

3.12 P-keymap

1
2
3
4
5
6
7
(defun gtrun-xah-fly-keys-P ()
  "key `P'"
  (interactive)
  (cond
   ;; ((eq major-mode 'dired-mode) (call-interactively 'd))
   ((eq major-mode 'dired-mode) (call-interactively 'xah-show-in-desktop))
   (t nil)))

3.13 –minus

1
2
3
4
5
6
7
(defun gtrun-xah-fly-keys-minus ()
  "key `-'"
  (interactive)
  (cond
   ;; ((eq major-mode 'dired-mode) (call-interactively 'd))
   ((eq major-mode 'dired-mode) (call-interactively 'vinegar/up-directory))
   (t nil)))

3.14 Color

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
;; (defun my-highlight-line-on () (global-hl-line-mode 1))
;; (defun my-highlight-line-off () (global-hl-line-mode 0))

;; (add-hook! 'xah-fly-command-mode-activate-hook 'my-highlight-line-on)
;; (add-hook! 'xah-fly-insert-mode-activate-hook  'my-highlight-line-off)

;; (defun my-xfk-command-color () (set-background-color "DeepSkyBlue"))
;; (defun my-xfk-insert-color () (set-background-color "IndianRed"))

;; (add-hook! 'xah-fly-command-mode-activate-hook 'my-xfk-command-color)
;; (add-hook! 'xah-fly-insert-mode-activate-hook  'my-xfk-insert-color)

4 define-key xah-fly-leader-key-map

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  (xah-fly--define-keys
   (define-prefix-command 'xah-fly-leader-key-map)
   '(
     ("DEL" . keyboard-quit)
     ("m" . magit-keys)
     ("o" . org-keys)
     ("s" . search-keys)
     ;;timer
     ("ti" . insert-current-date-time-inactive)
     ("ta" . insert-current-date-time-active)
     ("tc" . insert-current-date-time)
     ;;find file
     ("fr" . counsel-recentf)
     ("fp" . doom/find-file-in-private-config)
     ("<tab>" . spacemacs/alternate-buffer)
     ("ff" . counsel-file-jump)
     ("RET" . helm-bookmarks)
     ;; treemacs
     ("tt" . +treemacs/toggle)
     ("tf" . +treemacs/find-file)
     ;; helm
     ("bb" . switch-to-buffer)
     ("bs" . bookmark-set)
     ("bm" . bookmark-bmenu-list)
     ("bt" . bm-toggle)
     ;; dired
     ("dw" . dired-other-window)
     ("df" . dired-other-frame)
))

5 search-keys (leader-key to “s”)

[2020-09-23 Wed 03:25] <- define-key xah-fly-leader-key-map

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
  (xah-fly--define-keys
   ;; create a keymap my-keymap
   (define-prefix-command 'search-keys)
   '(
     ("a" . counsel-ag)
     ("r" . counsel-rg)
     ("y" . xah-search-current-word)
     ("m" . maple-iedit-match-next)
     ("i" . org-roam-insert)
     ("d" . sl-quick-insert-drawer-link)
     ("l" . sl-quick-insert-inline-link)
     ;;
     ))

6 org-keys (leader-key to “o”)

[2020-09-23 Wed 03:24] <- define-key xah-fly-leader-key-map

1
2
3
4
5
6
7
8
  (xah-fly--define-keys
   ;; create a keymap org-keymap
   (define-prefix-command 'org-keys)
   '(
     ("i" . org-clock-in)
     ("o" . org-clock-out)
     ("a" . org-agenda)
     ))

7 magit-keys (leader-key to “m”)

[2020-09-23 Wed 03:22] <- define-key xah-fly-leader-key-map

1
2
3
4
5
6
  (xah-fly--define-keys
   ;; create a keymap magit-keymap
   (define-prefix-command 'magit-keys)
   '(
     ("s" . magit)
     ))

8 end use-package config setting

1
2
;; FIXME: end line to xah-fly-keys
)

9 define global-set-key

1
2
3
(global-set-key (kbd "<f3>") 'gtrun/hydra-org-starter/body)
(global-set-key (kbd "<f4>") 'xah-fly-command-mode-activate)
(global-set-key (kbd "ESC ESC") 'keyboard-quit)

10 add hook to active xah-fly-keys insert or command mode

1
2
3
4
5
6
(add-hook! 'xah-fly-command-mode-activate-hook 'xah-fly-save-buffer-if-file)
(add-hook! 'magit-mode-hook 'xah-fly-insert-mode-activate)
(add-hook! 'snails-mode-hook 'xah-fly-insert-mode-activate)
(add-hook! 'sunrise-start-hook 'xah-fly-insert-mode-activate)
(add-hook! 'dired-hook 'xah-fly-insert-mode-activate)
(add-hook! 'color-rg-mode-hook 'xah-fly-insert-mode-activate)

✘ CANCELED 11 define-key xah-fly-keys-map(Insert mode)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
;; (defun xah-fly-insert-mode-init ()
;;   (xah-fly--define-keys
;;    xah-fly-key-map
;;    '(
;;      ("SPC" . nil)
;;      ("DEL" . nil)

;;      ("a" . nil)
;;      ("b" . nil)
;;      ("c" . nil)
;;      ("d" . nil)
;;      ("e" . nil)
;;      ("f" . nil)
;;      ("g" . nil)

;;      ("h" . nil)
;;      ("i" . nil)
;;      ("j" . nil)
;;      ("k" . nil)
;;      ("l" . nil)
;;      ("m" . nil)
;;      ("n" . nil)

;;      ("o" . nil)
;;      ("p" . nil)
;;      ("q" . nil)
;;      ("r" . nil)
;;      ("s" . nil)
;;      ("t" . nil)

;;      ("u" . nil)
;;      ("v" . nil)
;;      ("w" . nil)
;;      ("x" . nil)
;;      ("y" . nil)
;;      ("z" . nil)

;;      ("1" . nil)
;;      ("2" . nil)
;;      ("3" . nil)
;;      ("4" . nil)
;;      ("5" . nil)
;;      ("6" . nil)
;;      ("7" . nil)
;;      ("9" . nil)
;;      ("0" . nil)


;;      ("/" . nil)
;;      ("-" . nil)
;;      ("." . nil)
;;      ("," . nil)
;;      (";" . nil)
;;      ("'" . nil)
;;      ("[" . nil)
;;      ("]" . nil)
;;      ("\\" . nil)
;;      ("'" . nil)
;;      ("C-s" . swiper-isearch)
;;      ("C-c i" . counsel-imenu)
;;      ("C-v" . scrollkeeper-contents-up)
;;      ("C-x c" . xah-fly-command-mode-activate)
;;      ("<f3>" . gtrun/hydra-org-starter/body)
;;      ("<f4>" . xah-fly-command-mode-activate)
;;      ("<f5>" . awesome-tab-ace-jump)
;;      ;; more
;;      ))
;;   )