Emacs Keys: Key Sequence
Define Key Sequences
In emacs, you can define key sequences.
Suppose you want:
- F9 F6 for
visual-line-mode
- F9 f7 for
whitespace-mode
- F9 F8 for
toggle-frame-fullscreen
(progn ;; define key sequence (define-prefix-command 'my-keymap) (define-key my-keymap (kbd "<f6>") 'visual-line-mode) (define-key my-keymap (kbd "<f7>") 'whitespace-mode) (define-key my-keymap (kbd "<f8>") 'toggle-frame-fullscreen) (global-set-key (kbd "<f9>") my-keymap))
Press the leader key, then you can press Ctrl+h to see all available key/commands that follows.
Add other commands you use often, for example:
dired
〔see Emacs: File Manager, dired〕ibuffer
〔see Emacs: List/Switch Buffers〕list-bookmarks
〔see Emacs: Bookmark Tutorial〕recentf-open-files
〔see Emacs: Open Recently Opened File〕- Any command to activate a major mode that you use often.
- Any minor mode you want to toggle often.
More Examples of Key Sequence
;; Example of single key sequence (global-set-key (kbd "<f7>") nil) ; good idea to put nil to the starting key (global-set-key (kbd "<f7> <f8>") #'calendar) (global-set-key (kbd "<f7> <f9>") #'calc) ;; Example of sequence of single or chord keys (global-set-key (kbd "C-e") nil) ; good idea to put nil to the starting key (global-set-key (kbd "C-e a") #'calendar) (global-set-key (kbd "C-e SPC") #'calendar) (global-set-key (kbd "C-e C-a") #'calendar)
Typing Symbols Without Pressing Shift
(progn ;; define key sequence to type symbols (define-prefix-command 'my-symbols-map) (define-key my-symbols-map (kbd "1") "!") (define-key my-symbols-map (kbd "2") "@") (define-key my-symbols-map (kbd "3") "#") (define-key my-symbols-map (kbd "4") "$") (define-key my-symbols-map (kbd "5") "%") (define-key my-symbols-map (kbd "6") "^") (define-key my-symbols-map (kbd "7") "&") (define-key my-symbols-map (kbd "8") "*") (define-key my-symbols-map (kbd "0") ")") (global-set-key (kbd "<f9>") my-symbols-map))