Emacs: Alias

By Xah Lee. Date: . Last updated: .

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.

namealias
find-file-at-pointffap
bookmark-bmenu-listlist-bookmarks
re-search-forwardsearch-forward-regexp

Purpose of Alias

Useful user-defined alias for short 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 'vlm 'visual-line-mode)
(defalias 'ln 'global-display-line-numbers-mode)

Note: a key shortcut [Emacs: How to Define Keys] 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.

ErgoEmacs mascot-s276x226
Buy Xah Emacs Tutorial

Emacs Tutorial

Quick Start

Font

Split Window

File

Buffer

Find Replace

Copy/Paste

Unicode

Whitespace

Rectangle Edit

Line Wrap

Shell

View Special File

Editing Brackets

Org Mode

HTML

Emacs Efficiency

Misc