Back in July I wrote about using aliases to replace longer, hard to remember command names. Several of the commenters said that I should use smex to bring the wonders of Ido to extended commands. I finally got around to doing that and am now wondering why I waited so long. Now instead of relying on the qrr alias for query-replace-regexp I just type 【Meta+x】 qreg to get it. Sure, it’s a character longer but the same sort of thing works for all the commands, not just the ones I have aliases for. If you’re into adventure games, a little experimentation will usually find a shorter sequence. For instance 【Meta+x】 qex will also execute query-replace-regexp but the nice thing about smex is that you just need a general idea of what the command is to find it within 3 or 4 characters.
You can get smex via ELPA or from Github. Installation is simple. Just stash smex.el somewhere in your elisp load path and add
(require 'smex) (smex-initialize) (global-set-key (kbd "M-x") 'smex) (global-set-key (kbd "M-X") 'smex-major-mode-commands) (global-set-key (kbd "C-c C-c M-x") 'execute-extended-command)
to your .emacs or init.el file.
The key bindings are:
| key binding | action |
|---|---|
| 【Meta+x】 | find all commands |
| 【Meta+X】 | find mode specific commands |
| 【Ctrl+c Ctrl+c Meta+x】 | old extended command functionality |