next up previous contents index
Next: Getting Started Quickly in Up: Editing files with Emacs Previous: Editing files with Emacs

What's Emacs?

In order to get anything done on a computer, you need a way to put text into files, and a way to change text that's already in files. An editor is a program for doing this. Emacs is one of the most popular editors around--partly because it's very easy for a complete beginner to get actual work done with it. (The classic Unix editor, vi;, is covered in Appendix gif.)

To learn emacs, you need to find a file of plain text (letters, numbers, and the like), copy it to your home directorygif (we don't want to modify the actual file, if it contains important information), and invoke Emacs on the file:

screen6376

(Of course, if you decided to copy /etc/rc, /etc/inittab, or any other file, substitute that file name for README. For instance, if you cp /etc/rc ~/rc, then emacs rc.)

-to

-0.55in ``Invoking'' Emacs can have different effects depending on where where you do it. From a plain console displaying only text characters, Emacs will just take over the whole console. If you invoke it from X, Emacs will actually bring up its own window. I will assume that you are doing it from a text console, but everything carries over logically into the X Windows version--just substitute the word ``window'' in the places I've written ``screen''. Also, remeber that you have to move the mouse pointer into Emacs's window to type in it!

Your screen (or window, if you're using X) should now resemble Figure gif. Most of the screen contains your text document, but the last two lines are especially interesting if you're trying to learn Emacs. The second-to-last line (the one with the long string of dashes) is called the mode line.

;; figure6388
Figure: Emacs was just started with emacs README

In my mode line, you see ``Top''. It might be ``All'' instead, and there may be other minor differences. (Many people have the current time displayed in the mode line.) The line immediately below the mode line is called the minibuffer, or sometimes the echo area. Emacs uses the minibuffer to flash messages at you, and occasionally uses it to read input from you, when necessary. In fact, right now Emacs is telling you ``For information about the GNU Project and its goals, type C-h C-p.'' Ignore it for now; we won't be making much use of the minibuffer for a while.

Before you actually change any of the text in the file, you need to learn how to move around. The cursor should be at the beginning of the file, in the upper-left corner of the screen. To move forward, type C-f (that is, hold down the tex2html_wrap8336 key while you press ``f'', for ``forward''). It will move you forward a character at a time, and if you hold both keys down, your system's automatic key-repeat should take effect in a half-second or so. Notice how when you get to the end of the line, the cursor automatically moves to the next line. C-b (for ``backward'') has the opposite behavior. And, while we're at it, C-n and C-p take you to the next and previous lines, respectively.gif

Using the control keys is usually the quickest way of moving around when you're editing. The goal of Emacs is to keep your hands over the alpha-numeric keys of the keyboard, where most of your work gets done. However, if you want to, the arrow keys should also work.

-to

-0.55in In fact, when you're using X, you should be able to position the mouse pointer and click with the left button to move the cursor where you want. However, this is very slow--you have to move your hand all the way to your mouse! Most people who use Emacs primarily use the keyboard for getting around.

Use C-p and C-b to get all the way back to the upper-left corner. Now keep C-b held a little longer. You should hear an annoying bell sound, and see the message ``Beginning of buffer'' appear in the minibuffer. At this point you might wonder, ``But what is a buffer?''

When Emacs works on a file, it doesn't actually work on the file itself. Instead, it copies the contents of the file into a special Emacs work area called a buffer, where you can modify it to your heart's content. When you are done working, you tell Emacs to save the buffer--in other words, to write the buffer's contents into the corresponding file. Until you do this, the file remains unchanged, and the buffer's contents exist only inside of Emacs.

With that in mind, prepare to insert your first character into the buffer. Until now, everything we have done has been ``non-destructive'', so this is a big moment. You can choose any character you like, but if you want to do this in style, I suggest using a nice, solid, capital ``X''. As you type it, take a look at the beginning of the mode line at the bottom of the screen. When you change the buffer so that its contents are no longer the same as those of the file on disk, Emacs displays two asterisks at the beginning of the mode line, to let you know that the buffer has been modified:

screen6410

These two asterisks are displayed as soon as you modify the buffer, and remain visible until you save the buffer. You can save the buffer multiple times during an editing session--the command to do so is just C-x C-s (hold down tex2html_wrap8336 and hit ``x'' and ``s'' while it's down...okay, so you probably already figured that out!). It's deliberately easy to type, because saving your buffers is something best done early and often.

I'm going to list a few more commands now, along with the ones you've learned already, and you can practice them however you like. I'd suggest becoming familiar with them before going any further:

tabular6414


next up previous contents index
Next: Getting Started Quickly in Up: Editing files with Emacs Previous: Editing files with Emacs

Converted on:
Mon Apr 1 08:59:56 EST 1996