Contents
 
Introduction
To Emacs

Quick Intro To Emacs

Emacs is a very old program. It started life as a text editor. And it still does that today. You can start it up with a file name and it will start editing that file, or create it if it doesn't exist.

If you are running in an X-windows environment it will pop up a new window. Edit a file by typing

$ emacs file.dat &
It will look something like this:

Simple Editing

In emacs you can use the arrow keys to move the cursor around. Press a number or letter to insert a character. Easy.

Note that typing a character in the middle of some other characters pushes that line off to the right, inserting the characters, rather than overwriting them.

Buffers

If you want to edit more than one file at a time you dont start another copy of emacs - one emacs can happily deal with multiple files. Each file is edited in a buffer, and there are commands and menu options to switch between the different buffers. The current buffer is the one you can see. To save the file you are working on you can use the Files... Save Buffer option from the menu, or type C-x C-s

To load up another existing file into a new buffer, or start editing a new one, do C-x C-f and type the file name. This option is also on the Files... menu as Open File.... The file will be loaded and appear in a new buffer.

Switching Buffers

If you are looking at one file, and have another in a buffer that you cant see, then you can switch the current buffer - either choose the one you want from the Buffers... menu, or type C-x C-b for a buffer list. Then type C-x b and then enter the buffer name. Alternatively you can mouse-click with the middle button on the buffer name in the list.

Split Windows

You may have noticed that doing C-x C-b splits the window in two and displays the buffer list in one half and the current buffer in the other. You can use this to edit two files at once.

Edit a file in a buffer, and type C-x 2 - this splits the current window into two. You can switch between them by clicking in them, or doing C-x o, where you can think of o here standing for `other window'.

Then you can switch one window to another buffer with C-x b, or start editing a new file with C-x C-f

To undo the split, and get back to one window, do C-x 1.

All these split functions have equivalents under the Files... menu drop-down.

Marking, Cutting, and Pasting

If you want to move large chunks of text around, there are several ways of doing it:

Misc Motion

Here are some useful shortcuts:
C-a Start of Line
C-e End of Line
M-< Start of File
M-> End of File
C-k Delete to end of Line
You should also be able to use the Pg Up and Pg Dn keys to page up and down withing a file.

Completion

Do you tire of typing in long file names? Emacs has a completion feature. Type C-x C-f to edit an existing file, and type the first character of its name. Now press the TAB key. Emacs will fill in as many letters as possible. For example, if you want to edit thingy.tex, you type the first t and press TAB, and emacs will fill in thingy. - it stops here because there are several files that start with thingy. - there may be thingy.dvi, thingy.ps as well as thingy.tex, so at this point you type in the .tex extension and press return, and the file is loaded.

If you press TAB twice, then emacs will produce a buffer with all the possible completions in it. You can either then type the rest of the file name or click with mouse button 2 on the name in the completions list.

Completions also work on buffer names - if you are already editing a file in a buffer that you cant see, then type C-x b and then hit TAB for a completion list.

Panic!

The panic button in emacs is C-g - if emacs is spewing out error messages in its message line (bottom of the window) and you cant get it to do what you want, hit C-g until it starts behaving.

Undo

Done something you shouldn't have? Emacs keeps a full undo history. To undo each edit, type C-_ - thats Control, Shift and the -/_ keys simultaneously. If you undo all the way then emacs beeps, and starts redoing things.

Searching

The quickest way of searching for something in a file is to press C-s and then enter the search string. Emacs will find the next match with each character you type - this is called anincremental search. Press C-s again to find the next match. Emacs will beep and say "Failing i-search" in the message line if it cant find a match for your string. Hit the usual emacs panic button, C-g, to quit the search and return to where you were last typing, or press an arrow key to set the cursor at the search point.

More Information

I have put together a simple emacs reference with all the simplest commands on. If you want more details, there's the official emacs refcard, which is a PostScript file designed to be printed as a double-sided, three column reference card. 
Contents