Emacs: Command Name Alias
What is Alias
Alias is an alt name for function or command.
you can define an alias (in Emacs Init File) by:
(defalias 'old-name 'new-name)
there are many functions that have aliases by default. e.g.
name | alias |
---|---|
find-file-at-point | ffap |
bookmark-bmenu-list | list-bookmarks |
re-search-forward | search-forward-regexp |
Purpose of Alias
- make the name more intuitive. e.g.
bookmark-bmenu-list
→list-bookmarks
- override one function by another. e.g.
list-buffers
→ibuffer
- make the name shorter, so easier to type. e.g.
revert-buffer
→rb
Useful Alias for Command Names
you can use alias to shorten commands. For example, make frequently used commands just 1 or 2 letters.
put this in your Emacs Init File:
;; replace some commands by other (defalias 'list-buffers 'ibuffer) (defalias 'yes-or-no-p 'y-or-n-p) ;; make frequently used commands short (defalias 'qrr 'query-replace-regexp) (defalias 'lml 'list-matching-lines) (defalias 'dml 'delete-matching-lines) (defalias 'dnml 'delete-non-matching-lines) (defalias 'dtw 'delete-trailing-whitespace) (defalias 'sl 'sort-lines) (defalias 'rr 'reverse-region) (defalias 'rs 'replace-string) (defalias 'g 'grep) (defalias 'gf 'grep-find) (defalias 'fd 'find-dired) (defalias 'rb 'revert-buffer) (defalias 'sh 'shell) (defalias 'fb 'flyspell-buffer) (defalias 'sbc 'set-background-color) (defalias 'rof 'recentf-open-files) (defalias 'lcd 'list-colors-display) (defalias 'cc 'calc) ; elisp (defalias 'eb 'eval-buffer) (defalias 'er 'eval-region) (defalias 'ed 'eval-defun) (defalias 'eis 'elisp-index-search) (defalias 'lf 'load-file) ; major modes (defalias 'hm 'html-mode) (defalias 'tm 'text-mode) (defalias 'elm 'emacs-lisp-mode) (defalias 'om 'org-mode) (defalias 'ssm 'shell-script-mode) ; minor modes (defalias 'wsm 'whitespace-mode) (defalias 'gwsm 'global-whitespace-mode) (defalias 'ln 'global-display-line-numbers-mode)
💡 TIP: a key shortcut 〔see Emacs Keys: Define Key〕 is still less number of key strokes than M-x with 3 letter chars alias. However, alias is great for commands that you don't really use that frequently, but maybe once a day. It's easier to remember 3-letters abbrevs than an arbitrary key shortcut.