Help Topic: Survival Emacs
Maintained by: mikerb@mit.edu Get PDF
Survival Emacs
There are a ton of resources on the web to teach yourself emacs. And you will need to use a bit of your web/search savvy at some point to learn more. This help topic covers my own "survival emacs" tips I find myself repeating many times to new users. So before you're confronted with the reality that you're mostly on your own to teach yourself, here's a few things to get you going.
Opening and closing emacs [top]
If I were opening a text editor for the first time, the first thing I'd want to do is open a file, make some changes and play around, and exit without saving those changes. So that's the first thing we'll cover here:
- To open emacs, just type emacs testfile.txt on the command line.
- To close emacs, type C-x, C-c, which is shorthand for typing the Control and x key, followed by the Control and c key.
If you want to type in some changes in between opening and closing, just type, and move around with the arrow keys. If you want to exit without saving the changes, just type C-x, C-c as before, and when you're prompted with:
Save /home/you/testfile.txt? (y, n, !, ., q, C-r, d, C-h)
type 'n', you don't want to save changes, and type yes when you are subsequently questioned if you really want to exit without saving changes.
Saving Changes [top]
Now that you know how to open an edit session and exit, you may want to actually save some changes! At any time just type C-x, C-s to save changes. In case you're ever wondering if there are any "pending" changes to be saved, you can always look at the bottoms of the emacs window for a line that looks something like:
--:**- testfile.tex All L1 (Tex)-----------------------------
If you see the asterisks on the left, then the file you are editing has pending changes that have not yet been saved. After you save the file, you should see the line change to something like the below, with the asterisks now gone:
--:--- testfile.tex All L1 (Tex)-----------------------------
Get Out of Jail Free Card [top]
Here's an emacs command you should know from day one. Now that you've experienced emacs commands such as C-x, C-s (Save) and C-x, C-c (Quit), you may find yourself fat-fingering something else by mistake. Here's how to set things right:
- Type C-g at any time to quit any emacs command you may be in the middle of, and return to the normal editing mode.
For example, try typing C-x, C-d which is right between the Save and Quit commands. You'll see the cursor moves to the buffer at the bottom of the emacs window with something like:
List directory (brief): ~/
which is harmless enough (it just lists the contents of the directory shown). But it's not what you wanted, and now your cursor is down at the bottom and emacs is apparently looking for an answer from you. Just type C-x, C-g to get back to editing the file.
Cut and Pasting [top]
Copy/Cut and paste in emacs is known as "kill" and "yank":
- C-k to "kill" everything to the right of the cursor and hold it in an internal buffer. (Hint: type it twice to kill the line and the line feed at the end.
- C-y to "yank" everything previously killed and in the internal buffer.
Page built from LaTeX source using texwiki, developed at MIT. Errata to issues@moos-ivp.org. Get PDF