A Beginner's Guide to Using EMACS

Most people, upon hearing that I'm writing a beginner's guide to EMACS, laugh at me. That's understandable. If you are reading this document, then EMACS was not written for you. EMACS was written by a man who believes that computers are for a select, and elite, group of people. So why should you bother to use EMACS? Because it is the most powerful editor you will ever use. If you can get past its quirks and archane commands, you can accomplish anything with documents. For example, EMACS is used to: Of course, there's more, but you get the idea. EMACS is much more than just an editor. I'm not sure what it is, but just an editor it is not. Whatever, once you learn the power of EMACS, you will never look back.

EMACS is a graphical editor that has colors, menus, and scroll bars. However, most people never see any of that. What you probably see when you start emacs is a blank screen with a white bar almost at the last line. Perhaps there is some copyright stuff that goes away when you press a key. Too bad, that makes emacs a little more difficult to use. However, that's the version this guide is going to cover.

Starting EMACS

Starting EMACS isn't all that hard. At the prompt, type emacs.
That's it. That's all there is to it. It has to all be in lowercase. You can specify the names of files you want to edit after the name, but that's it. (Remember to put a space between emacs and the name of the file!) If you don't know what a prompt is, read the tutorial on using UNIX. Example
$ emacs my_doc.txt
You'll see something like this on the screen:
Screen shot of emacs starting up on an IBM.
If it looks even similar to this, you did it!

The parts of the Screen

The major parts of an EMACS screen are clearly labeled in the diagram below.

A screen shot of emacs, with the parts labeled.
Here, you can clearly see what the name of everything is.

Buffers and files

What is a buffer? Well, EMACS keeps everything in a buffer. If you open a file in EMACS, EMACS opens a buffer, names it the same name as the file, and loads the file into the empty buffer. However, buffers can also contain directory listings, informational messages which won't fit in the mini-buffer, help messages, or anything else that EMACS wants to put in them. Usually, a buffer which isn't associated with a file will have stars '*' around the name. Buffers are a powerful concept. You can have as many buffers open at the same time as you want; it's not hard to switch between buffers. You can also have as many buffers on the screen at the same time as you wish -- although if you have too many, each buffer gets too small to see anything.

A file is a document stored on the disk. When you save a document, you are saving it to a file. Then, later, you can load it again.

A directory is a way of organizing files. A directory can contain files, or other directories.

Quick EMACS Commands

Quitting EMACS:

Quit: Ctrl-x Ctrl-c
I pushed the wrong key. Help!: Ctrl-g

Working with files:

Load a file: Ctrl-x Ctrl-f
Load a directory: Ctrl-x Ctrl-f
New file: Ctrl-x Ctrl-f
Save a file: Ctrl-x Ctrl-s
Save all open files:Ctrl-x s
Save the file with a new nameCtrl-x Ctrl-w

Dealing with Buffers

Switch buffers: Ctrl-x b
Close buffer: Ctrl-x k
Split current bufferCtrl-x 2
Make current buffer the only one on screenCtrl-x 1
Switch between the buffers on-screenCtrl-x o

Cutting and pasting

Set mark: Ctrl-[SPACE]
Cut and save text from here to mark: Ctrl-w
Paste saved text: Ctrl-y
Cut text from the cursor to the end of the line: Ctrl-k