Last post, I talked about command-frequency-mode - both how to set it up and what it does. After I executed approximately 150000 commands, I found the most frequent ones, hoping to discover inefficiencies among my editing style that I could fix. This post has the top 10 different types of commands I tend to use, as long as subcommands and default keybindings. If you’re looking for a list of possible commands to use, you can just use these tables to increase your emacs knowledge. You can find more about these commands with C-h f, describe-function, and entering the command name.
Insertion
| 72045 | 46.17% | self-insert-command | Many |
| 896 | 0.57% | comint-send-input | RET |
| 629 | 0.40% | newline-and-indent | C-j |
| 406 | 0.26% | newline | RET |
| 323 | 0.21% | slime-space | SPACE |
| 215 | 0.14% | c-electric-paren | (,) |
| 176 | 0.11% | c-indent-new-comment-line | C-M-j |
| 138 | 0.09% | slime-repl-return | RET |
| 118 | 0.08% | indent-new-comment-line | C-M-j |
The most frequent type of commands I use are, of course, related to inserting text. Self-insert-command is the basic command that insertion keys are bound to, which merely inserts the character pressed into the current location. The other input commands on the list are related either to inserting newlines, or special insert commands that do things such as indent the current line as well as insertion. Comint-send-input, for example, will execute the command you typed in as well as entering a blank line. Many of these commands will indent as well as adding a newline. indent-new-comment-line will also continue comments.
Movement
| 18034 | 11.56% | next-line | C-n |
| 16036 | 10.28% | previous-line | C-p |
| 1565 | 1.00% | forward-char | C-f |
| 2099 | 1.35% | backward-char | C-b |
| 1497 | 0.96% | backward-paragraph | M-{ |
| 1461 | 0.94% | move-end-of-line | C-e |
| 1454 | 0.93% | dired-previous-line | p |
| 1270 | 0.81% | dired-next-line | n |
| 1162 | 0.74% | back-to-indentation | M-m |
| 982 | 0.63% | backward-word | M-b |
| 875 | 0.56% | forward-paragraph | M-} |
| 525 | 0.34% | end-of-buffer | M-> |
| 497 | 0.32% | forward-word | M-f |
| 370 | 0.24% | end-of-visual-line | C-e |
| 308 | 0.20% | beginning-of-buffer | M-< |
Movement commands are next frequent. These are mostly standard movement keys - either moving to the next of previous line, word, character, or paragraph are all standard commands that are some of the first you learn. Back-to-indentation I use probably more than most people, since I have it rebound to C-a instead of having that be the default key beginning-of-line. I tend to go to the end and beginning of buffer quite a bit, so these showed up.
Deletion
| 8218 | 5.27% | delete-backward-char | DEL |
| 3498 | 2.24% | backward-delete-char-untabify | DEL |
| 666 | 0.43% | c-electric-backspace | DEL |
| 452 | 0.29% | kill-and-join-forward | C-k |
| 333 | 0.21% | kill-line | C-k |
| 329 | 0.21% | backward-kill-word | C-DEL |
| 139 | 0.09% | kill-word | M-d |
| 118 | 0.08% | kill-visual-line | C-k |
| 176 | 0.11% | delete-char | DEL |
Various ways of deleting text came in as the next most popular character. Most of these are more standard commands that everyone should know, and the various equivalents in other modes. Kill-line does sometimes act differently than most people expect, not killing newlines by default, but I prefer it’s default behaviour in most cases. It will kill from point to end of line, allowing you to replace whatever you just deleted.
Buffer Control
| 2069 | 1.33% | other-window | C-x o |
| 1376 | 0.88% | ido-exit-minibuffer | C-g |
| 769 | 0.49% | ido-switch-buffer | C-x b |
| 613 | 0.39% | ido-delete-backward-updir | DEL |
| 426 | 0.27% | ido-kill-buffer | C-x k |
| 312 | 0.20% | ido-find-file | C-x C-f |
| 212 | 0.14% | ido-next-match | RIGHT |
| 111 | 0.07% | dired-advertised-find-file | v |
These commands all relate to switching buffers and opening new windows. This allows you to have multiple buffers open and displayed at a time, to switch which buffers are displated, and create and kill existing buffers. These are not commands I’d expect beginning emacs users to learn, but I’d recommend anyone using emacs seriously to learn how to at least split the screen and use multiple buffers at a time. Most of these are Ido commands, which I talk about in my blog post here, but worse versions of the commands are available with the same keybindings if you haven’t enabled Ido.
Search
| 1155 | 0.74% | isearch-printing-char | Many |
| 659 | 0.42% | abort-recursive-edit | C-] |
| 273 | 0.17% | isearch-other-control-char | Many |
| 196 | 0.13% | isearch-repeat-forward | C-s |
| 174 | 0.11% | isearch-repeat-backward | C-r |
| 164 | 0.11% | isearch-forward | C-s |
| 121 | 0.08% | isearch-backward | C-r |
Incremental search is just amazing. If you want to search for a word in your buffer, you can just press ‘C-s’ and start typing, and it will search as you type. C-s will go to the next match, and C-r will reverse direction and search backwards. You can also grab the word under point with C-w once you have entered isearch-mode by pressing C-s. The one thing that suprised me here was the large portion of abort-recursive-edits, since I almost never intentionally enter recursive edits.Recursive edits allow you to essentially suspend a search, edit the buffer some, and then resume the search. I should probably use these more than I do, but aborting recursive edit’s shouldn’t account for .42% of my commands.
History
| 554 | 0.36% | undo | C-/ |
| 291 | 0.19% | comint-previous-input | M-p |
| 108 | 0.07% | slime-repl-backward-input | M-p |
Now we’re getting to categories that are less than 1% of my total editing commands. These commands all involve using previously-entered data, either by undoing or using previous history. Undo works differently in emacs than most editors; in emacs, you can undo to any point in your editing of a buffer, one command at a time. However, there is no redo; if you want to redo, you need to perform a command and then undo twice after undoing. This will first perform the command, undo the command, and then undo the first undo. I really think there should be some type of redo command, but I’ve tried to implement it and it’s unfortunately rather difficult to get one that works well. The other two commands are all more standard terminal history commands, with shell-mode and slime specifically.
Completion
| 382 | 0.24% | minibuffer-complete-word | SPACE |
| 573 | 0.37% | pabbrev-expand-maybe | TAB |
| 197 | 0.13% | comint-dynamic-complete | TAB |
Completion is another task I use a fair amount. One thing that immediately springs to mind is that yasnippet isn’t used at all here; I should make more extensive use of this. Pabbrev I’ve talked about here, and the other two commands in this category are fairly standard completion commands - comint-dynamic-complete is standard terminal tab-completion, whereas most people have probalby encountered minibuffer completion.
Miscellaneous
| 1063 | 0.68% | save-buffer | C-x C-s |
| 568 | 0.36% | cua-set-mark | C-SPACE |
| 418 | 0.27% | execute-extended-command | M-x |
| 373 | 0.24% | eval-last-sexp | C-x C-e |
| 312 | 0.20% | keyboard-quit | C-g |
| 423 | 0.27% | cua-paste | C-y |
| 165 | 0.11% | slime-eval-last-expression | C-x C-e |
| 122 | 0.08% | cua-copy-region | M-w |
| 107 | 0.07% | dired-mark | m |
These are just miscellaneous commands that didn’t really fit into any category. Saving the buffer, setting the mark, M-x, C-y, and M-w are all command any basic emacs user should know. The cua-paste and cua-copy-region are just cua’s rebindings of kill-ring-save and yank, which function in pretty much the same way. Eval-last-sexp and slime-eval-last-expression are commands that are very useful for editing lisp; they will evaluate the expression right before point. Dired-mark is a dired command I’ve blogged about here.
Conclusions
Looking over these, there are several inefficiencies I noticed in the way I use emacs.
1) I use next-line and previous-line far too much. These should not be 10% of the commands I issue each. If I am moving around the buffer this much, I should learn more efficient ways to do so - either by using search more, or prefix keys, or just using forward-paragraph more.
2) My most frequent deletion command is by far deleting a single character. I find it hard to believe that this is the most common situation by that much, which means I should be using either kill-word more, or being more efficient at learning when i should mark a region and kill a region that way instead of just backspacing over it.
3) For someone who doesn’t consciously remember *ever* using a recursive edit in the time period I was recording this, I use way too many abort-recursive-edit calls. I need to find out how I’m entering recursive edits, and do that less. I’m not precisely sure how I’ll do this - maybe by defadvicing the recursive edit entry to notify me when it happens - but it really is something I should work on.
Even fixing just these three things seems likely to increase my editing proficiency with emacs by around 5%, so I think this was a valuable exercise. I highly recommend you doing the same - the process is described in my last blog entry, and it is quite simple to have runing for a few weeks while it gathers statistics. I’m probably going to do this again in a few months, hopefully once I’ve fixed or at least improved upon the three issues mentioned above.
Tags: emacs
[...] more here: Top 10 Emacs Commands Tags: academics, autoindentation, buffer-control, completion, conclusions, deletion, editing, [...]
Nice analysis, I’ve got the command frequency running myself and look forward to seeing what I can learn (and compare to your usage as well).
Regarding ‘redo’, I think the problem boils down to Emacs’s undo mechanism - namely that it stores everything (the whole undo an undo). If the undo mechanism were changed to actually remove events from the history (and save them off to a redo list somewhere), then I think ‘redo’ could fit.
But, I imagine you’d then suffer the same limitation all the other undo/redo mechanisms seem to suffer, namely, when you do something other than ‘redo’ after an ‘undo’ you have to clear out the redo list. And then you’ve lost the ability to get back to all the configurations the buffer had…
That’s my thought at least. Emacs’ undo is confusing at first, but I like the power it holds.