Emacs has way too many keyboard shortcuts to memorize. Fortunately, you can call commands by name by typing M-x and the name of the command. M- stands for the Meta key. If your keyboard does not have a Meta key (and most don’t, these days), use Alt or Option. For example, on a PC keyboard, you can type Alt-x. Alternatively, you can replace Meta with ESC. M-x then becomes ESC x.
If you know the name of the command to execute, you can type it after M-x, and then press RET (the Return key, which is the same as the Enter key). For example, M-x find-file opens a file. M-x save-buffer saves the current file. You can use TAB to complete words. Use <up> and <down> to go through your command history.
What if you don’t know the name of the command to execute? You can use M-x apropos-command to search for the command using keywords. If you know the keyboard shortcut or you can find the command on a menu, you can also use M-x describe-key and then do the keyboard shortcut or select it from the menu.
If a command you execute has a keyboard shortcut, it will flash briefly at the bottom of your screen. For example:
You can run the command `find-file' with C-x C-f
Using TAB for completion can be a little slow. Here are two ways to make that and a whole lot of other things faster: ido and helm. To explore these approaches, you will need to add the MELPA package repository to your configuration. To set that up, add the following to the beginning of your
(package-initialize) (add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)
Then use M-x eval-buffer to load the changes into your current Emacs, and use M-x package-refresh-contents to reload the list of packages.
This is what completion with Helm looks like:
Figure 2: Helm
Use M-x package-install to install the
helm package. Then you can try it out with M-x helm-mode . After you start Helm mode, try M-x again. You can type in multiple words to search for a command, and you can use <up> and <down> to go through completions. Use M-p and M-n to go through your command history.
If you like it, here’s some code that you can add to your
~/.emacs.d/init.el file to load it automatically next time, and to tweak it for more convenience.
(require 'helm-config) (helm-mode 1)
Use M-x eval-buffer to load your changes.
If you change your mind and want to disable
helm-mode, you can toggle it off with M-x helm-mode .
If you like how that works, you may want to
(global-set-key (kbd "M-x") 'helm-M-x). If you do, you’ll be able to see keybindings when you call commands with
M-x. Note that if you want to use a prefix argument (ex:
C-u), you will need to do that after calling
M-x instead of before.
Ido is like Helm, but it takes a different approach. Here’s what this combination will get you:
Figure 1: ido, smex, ido-vertical-mode, and flx-ido
If you want to give this a try, remove or comment out
(helm-mode 1) from your
~/.emacs.d/init.el (if you added it), and disable helm-mode if you still have it active from the previous section.
To set Ido up, use M-x package-install to install
After the packages are installed, add the following code to your
(ido-mode 1) (require 'ido-hacks nil t) (if (commandp 'ido-vertical-mode) (progn (ido-vertical-mode 1) (setq ido-vertical-define-keys 'C-n-C-p-up-down-left-right))) (if (commandp 'smex) (global-set-key (kbd "M-x") 'smex)) (if (commandp 'flx-ido-mode) (flx-ido-mode 1))
Use M-x eval-buffer to load your changes, then try M-x again. You should now have much better completion. You’ll be able to call commands by typing in part of their names. Use <up> and <down> to go through the completion options, and use <left> and <right> to go through your history.
Try it for a week. If you like it, keep it. If you don’t like it, try the Helm approach.
When you learn keyboard shortcuts, try to remember the names of the commands as well. You can do that with C-h k (
describe-key). For example, M-x calls the command
execute-extended-command. That way, even if you forget the keyboard shortcut, you can call the command by name.
If you forget the name of the command and you don’t know the keyboard shortcut for it, you can look for it in the menus or in the help file. You can open the help file with C-h i (
info). You can also use M-x apropos-command to search through the commands that you can call with M-x.
Make your own cheat sheet with frequently-used keyboard shortcuts and commands to help you learn more about Emacs. Good luck!
I’m Sacha Chua and this is an Emacs Basics episode on using the mouse. The best way to use Emacs is to master the keyboard shortcuts, but when you’re starting out, don’t worry about them yet. You might find yourself using the mouse a whole lot more than you used to, but over time, you will learn more and more keyboard shortcuts as you get used to Emacs. So let’s say that you’re just starting out. What are some of the things that you can do right away to get the hang of using Emacs?
The Emacs tutorial is a great place to start. You can get to that by clicking on the Emacs tutorial link on the splash screen. If you’ve done the tutorial before, it will offer to let you resume at that point. If you don’t have the splash screen handy, you can also get to the tutorial from Help > Emacs tutorial. Go through this and you’ll learn a lot of the common keyboard shortcuts that will come in handy.
The toolbar and the menu will also give you quick access to a lot of common commands. If you’d like to create a new file or open an existing file, you can click on the New file icon located in the top left. You can specify the file, and if the file doesn’t exist yet, it will create it. To save the file, click on the Save icon. If you’d like to close a file, just click on the X mark. You can open the file again using the toolbar icon.
To copy and paste, use your mouse to select a region of text, then copy or cut it. Then you can paste it wherever you want. You could also search for text. Click on that search button and start typing what you’re looking for. It will highlight the search results. Press Ctrl+s to search for the next instance. Press Enter to stop searching.
The menus also offer a lot of other commands. For example, you can insert a file. You can save the current buffer with another file name. You can split your windows so you can see more than one file at the same time. If you’d like to close a window and go back to having one file across your entire screen, you just have to use File > Remove other windows. To switch between the files you have open, use the Buffers menu. Explore the menus for other options.
One of the interesting things in Emacs is that you can copy or cut multiple things and then paste them without having to keep copying or cutting each time. For example, if I copy this, then Paste will paste that. But you could also access the things that you copied or cut previously. Just click on Edit > Paste from kill menu, then select the item you want to paste.
There are lots of other tools that are available in Emacs. The availability of these tools may depend on what else you’ve installed. Again, for more information, check out the Emacs tutorial or read the Emacs manual.
Meloney Hall interviewed me about sketchnoting. I managed to listen, talk, and sketch while doing this. Boggle! Although talking interferes a little with writing words, so my notes become more graphical. Hmm, maybe that’s a way for me to experiment with more graphical notes… =)
In this episode, we interviewed Justin McCurry (RootOfGood) about retiring at 33. He’s been learning how to relax and enjoy life as a stay-at-home dad, and has mostly gotten the hang of it six months in. =) You can download the MP3 from archive.org
Other resources we mentioned:
In this episode, Jordan Read and I talk about our plans for a new Google Hangout on Air / podcast show around financial independence and retiring early. Check out the Mustachians community on Google+ for upcoming events. The next show is tonight (March 13, Thursday) at 8 PM EDT. We’ll be talking to Justin from Root of Good, who’s six months into early retirement. =) To subscribe to this podcast, add this feed to your reader: http://sachachua.com/blog/category/frugal-fire/podcast Download the MP3