From: Xah Lee
Subject: Emacs's Command Frequency
Date: 
Message-ID: <1185464312.809909.89810@x40g2000prg.googlegroups.com>
Emacs's Command Frequency

Xah Lee, 2007-07

(A formated HTML version of this article is available at
http://xahlee.org/emacs/command-frequency.html
)

In emacs, each key press actually invokes a command. (For example,
typing “a” actually invokes the command “self-insert-command”. Typing
Ctrl+f invokes the command forward-char. Typing Alt+x invokes execute-
extended-command.)

A important aspect in designing a keyboard shortcut set, for a
application that has intensive, repetitive, prolonged human-machine
interaction (such as coding and text editing), is to consider
ergonomic principles. Specifically: allocate keyboard shortcuts for
the most frequently used commands, and, the top most frequently used
commands should have most easily-pressed keystrokes. For example, they
should be on the home row.

This page lists the order of commands used in emacs in their frequency
of use.

COMMAND FREQUENCY LIST

The following frequency list is based on a single user (me) for about
a week's use of emacs in 2006-10, with about 30k accumulated
keystrokes. Because it is based on a single user, the frequency order
is biased towards the user's editing tasks and habits. However, it can
give a rough indication on which commands are more frequently used.

Commands that involves moving the cursor, are colored red. Commands
that modifies text or related to editing (such as set-mark-command,
copy, paste, delete-word), are colored blue. Commands that results
from the same keystroke are grouped together (For example, delete-
backward-char, backward-delete-char-untabify, python-backspace, cperl-
electric-backspace are all grouped together because they are all just
the Backspace key. Another example: isearch-forward, isearch-printing-
char,isearch-repeat-forward, isearch-abort... are grouped together
because with respect to editing they are all just a Find command.).

29758	self-insert-command
  978	newline

10149	next-line
  380	dired-next-line

7912	previous-line
  168	dired-previous-line

4699	backward-word
3702	forward-word

2703	kill-region

1754	delete-backward-char
  771	backward-delete-char-untabify
  53	python-backspace
  17	cperl-electric-backspace

1953	forward-char
1526	backward-char

1217	save-buffer
  62	center-line (actually aliased to save-buffer by customization)

832	yank

740	kill-buffer-silently * (kills the current buffer without
prompting, unless it is not saved)
613	scroll-up

455	isearch-forward
  114	isearch-backward
    2492	isearch-printing-char
    285	isearch-other-meta-char
    271	isearch-other-control-char
    139	isearch-repeat-forward
    91	isearch-repeat-backward
    16	isearch-abort

412	undo
412	other-window
390	previous-history-element

373	delete-char
344	scroll-down
301	minibuffer-complete
290	execute-extended-command
288	set-mark-command
283	dired

251	move-beginning-of-line
241	dired-advertised-find-file
210	find-file
183	beginning-of-buffer
170	revert-buffer
164	move-end-of-line
159	recenter
153	kill-ring-save
144	extend-selection *
136	delete-other-windows
131	eval-last-sexp
126	end-of-buffer
122	mouse-drag-region
117	split-window-vertically
114	minibuffer-keyboard-quit
104	ibuffer-mark-for-delete
102	fill-paragraph
98	mouse-set-point
96	keyboard-quit
91	exit-minibuffer
88	shell-command
83	just-one-space
79	describe-function
74	describe-key
72	lisp-indent-line
65	grep
64	browse-url-of-buffer
62	delete-window
60	mark-whole-buffer
52	sgml-close-tag
51	handle-switch-frame
50	(lambda nil (interactive) (scroll-down 1))
47	dired-do-query-replace-regexp
45	(lambda nil (interactive) (scroll-up 1))
37	shell-command-on-region
37	next-buffer
37	Info-follow-nearest-node
33	html-paragraph
32	query-replace
30	backward-paragraph
30	forward-paragraph
26	dired-mark-files-regexp
26	previous-buffer
26	bookmark-bmenu-list
25	Info-up
23	ibuffer-forward-line
23	bookmark-bmenu-this-window
23	switch-to-buffer
22	query-replace-regexp
20	minibuffer-complete-and-exit
19	ibuffer-backward-line
18	ibuffer
18	string-rectangle
17	ispell-word
17	sgml-slash
16	other-frame
16	universal-argument-other-key
16	universal-argument
15	compile-goto-error
15	next-history-element
14	beginning-of-defun
13	ffap
12	ibuffer-mark-forward
12	dired-do-rename
12	replace-string
11	set-variable
11	backward-up-list
11	apropos-command
11	command-frequency-display
10	ibuffer-visit-buffer
10	ibuffer-update
10	dired-do-copy
...

SOME SUMMARY

Based on the list, with consideration of assigning keyboard shortcuts
to the most frequently used commands, we can group the most frequently
used commands into 3 categories: (1) Commands that moves the cursor.
(2) Commands that changes text (such as copy, paste, delete-backward-
char, backward-kill-word). (3) Other.
The Cursor Moving Commands

Moving cursor by character:

10149	next-line
  380	dired-next-line

7912	previous-line
  168	dired-previous-line

1953	forward-char
1526	backward-char

Moving cursor by word, line, sentence, paragraph, screen-full, or
beginning/ending of a file:

4699	backward-word
3702	forward-word

251	move-beginning-of-line
164	move-end-of-line

0	forward-sentence
0	backward-sentence

0	forward-paragraph
0	backward-paragraph

613	scroll-up (page down)
344	scroll-down (page up)

183	beginning-of-buffer
126	end-of-buffer

Other:

159	recenter
0	move-to-window-line, M-r
0	tab-to-tab-stop, M-i
0	back-to-indentation, M-m

Text Editing Commands

Single Character Deletion invoked by the Backspace key or (forward)
Delete key, or emacs's shortcut Ctrl-d.

1754	delete-backward-char
  771	backward-delete-char-untabify
  53	python-backspace
  17	cperl-electric-backspace

373	delete-char

Deletion by word, line, paragraph

?	backward-kill-word
?	kill-word

?	kill-line

0	backward-kill-paragraph
0	kill-paragraph

For some reason, the program that compiled the frequency list, lumps
commands backward-kill-word, kill-word, kill-line, kill-region, all
into just kill-region.

Mark, Copy, Cut, Paste

288	set-mark-command
153	kill-ring-save (copy)
2703	kill-region (includes: backward-kill-word, kill-word, kill-line)
832	yank (paste)
2	yank-pop (paste previous)

Undo.

412	undo

Other.

102	fill-paragraph

32	query-replace
22	query-replace-regexp
18	string-rectangle
12	replace-string

7	downcase-word, M-l
5	upcase-word
6	upcase-initials-region

0	translate-region
0	transpose-chars
0	transpose-words
0	transpose-lines
0	transpose-paragraphs
0	transpose-regions
0	transpose-sentences
0	transpose-sexps
0	transpose-subr
0	transpose-subr-1

0	comment-dwim, M-;
0	indent-new-comment-line, M-j

0	zap-to-char, M-z

0	tags-loop-continue, M-,
0	find-tag, M-.
0	dabbrev-expand, M-/

HOW THE LIST IS COMPILED

The above frequency list is a edited version of the output by the
elisp program that counts invoked commands.

The editing are done as follows: Commands called less than 10 times
are removed. Customized Commands that are not related to general emacs
use are also deleted. (for example, insert-p inserts a specialized
HTML markup, “,bbedit” opens the current buffer in a Mac text editor
or Finder). Customized command that are related to general emacs use,
or as a substitute to other emacs commands, are not removed. For
example, i have defined kill-buffer-silently, which is similar to kill-
buffer except that it does not prompt unless the file is not saved.
Uninteresting commands in this context, such as mwheel-scroll, nil
(probably due to canceled command or error), ignore, are removed.

The complete, unedited raw output is here: command-frequency_out.txt.

The program that counts the command is here: command-frequency.el.
Once you run the program, each command you use in emacs is counted.
When you want, type Alt+x command-frequency-display to list the
commands you have used, and the number of times they are called.

  Xah
  ···@xahlee.org
∑ http://xahlee.org/