Emacs: Add Custom Keys to Enhance Productivity

Advertise Here

, 2005, …,

Here are some practical emacs keybinding suggestions to enhance productivity. If you don't know the basics of how to define keys, see: Emacs: How to Define Keyboard Shortcuts.

Common Keys

(global-set-key (kbd "C-z") 'undo) ; 【Ctrl+z】
(global-set-key (kbd "C-Z") 'redo) ; 【Ctrl+Shift+z】

(global-set-key (kbd "<home>") 'move-beginning-of-line)
(global-set-key (kbd "<end>") 'move-end-of-line)

(global-set-key (kbd "<home>") 'beginning-of-buffer)
(global-set-key (kbd "<end>") 'end-of-buffer)

Insert Special Characters

You can create a shortcut to insert frequently used Unicode characters. You can add few chars, or a systematic character set.

;; example of systematic keys to insert math symbols
(global-set-key (kbd "<kp-6>") "→") ; number keypad 6
(global-set-key (kbd "M-i a") "α") ; 【Alt+i a】
(global-set-key (kbd "M-i b") "β")
(global-set-key (kbd "M-i t") "θ")
;; some Hyper keys to insert Unicode chars
(define-key key-translation-map (kbd "H-3") (kbd "•")) ; bullet
(define-key key-translation-map (kbd "H-4") (kbd "◇")) ; white diamond
(define-key key-translation-map (kbd "H-$") (kbd "◆")) ; black diamond
(define-key key-translation-map (kbd "H-5") (kbd "†")) ; dagger
(define-key key-translation-map (kbd "H-%") (kbd "‡")) ; double dagger

If you do math a lot, you might try a more complete system. See: Emacs Unicode Math Symbols Input Mode (xmsi-mode).

To define Super & Hyper key, see: Emacs: How to define Super & Hyper Keys.

See also: Emacs and Unicode TipsEmacs: Remapping Keys Using key-translation-map.

Remap Frequently Used Shortcuts

;; make cursor movement keys under right hand's home-row.
(global-set-key (kbd "M-i") 'previous-line) ; was tab-to-tab-stop
(global-set-key (kbd "M-j") 'backward-char) ; was indent-new-comment-line
(global-set-key (kbd "M-k") 'next-line) ; was kill-sentence
(global-set-key (kbd "M-l") 'forward-char)  ; was downcase-word

(global-set-key (kbd "M-SPC") 'set-mark-command) ; was just-one-space

For a more systematic change, see: ErgoEmacs Keybinding.

Template Insertion

Define keys to insert text you frequently use. Header, footer, signature, copyright template, etc.

(global-set-key (kbd "<f5>") 'insert-my-header)
(global-set-key (kbd "<f6>") 'insert-my-footer)
(global-set-key (kbd "<f7>") 'insert-signature)

;; example of defining a template insertion command
(defun 'insert-paragraph-tag ()
  "Insert <p></p> at cursor point."
  (interactive)
  (insert "<p></p>")
  (backward-char 4))

If you want a elaborate template system for programing, you should use YASnippet instead. See: Emacs Templates with YASnippet.

Emacs: Adding Web Browser Nav Keys to Info-mode

You can make your mouse's thumb buttons do backward and forward. See: Adding Web Browser Nav Keys to Info-mode.

Open Frequently Used Files

(global-set-key (kbd "<f5>") 'open-unicode-template)

(defun open-unicode-template ()
 "Open a file containing frequently used Unicode chars"
 (interactive)
 (find-file "~/web/emacs/unicode.txt"))

I press 1 button on number pad to open ibuffer, bookmark, recently opened file list.

;; some number pad keys to open some files
(global-set-key (kbd "<kp-5>") 'recentf-open-files) ; numpad5
(global-set-key (kbd "<kp-7>") 'bookmark-bmenu-list)
(global-set-key (kbd "<kp-8>") 'ibuffer)

Here's some hotkey i use to open specific files i use few times a hour.

(global-set-key (kbd "<C-kp-9>") 'open-twitter) ; Ctrl+ numpad9
(global-set-key (kbd "<C-kp-6>") 'open-todo)

Note: depending on what OS and what emacs distro you are using, defining keys for the numeric keypad may not work.

You can see all my personal keybinding here: xah_emacs_keybinding.el (they change about weekly).

blog comments powered by Disqus