Inserting and deleting text
To insert text into a buffer, place the cursor where you want to start inserting text, and start typing away.
If you want to insert the contents of another file into the current buffer, place the cursor at the desired insertion point, and type Control-X-I. Emacs will ask you for the name of the file you wish to insert.
You may also insert text by cutting it from one place, and pasting it at the insertion point. See the next section for information on cutting and pasting.
Deleting text is easy. As you'd expect, the delete key deletes backward one character. Here are some other ways to delete text:
- Control-D deletes forward one letter.
- Control-K deletes from the point to the end of the line.
- ESCAPE-D deletes forward one word.
- ESCAPE-delete deletes backward one word.
Cutting and pasting text regions
Emacs allows you to select a region of text, and perform cut and paste operations on the region. It uses a temporary storage area called the "kill bufferto allow you to store and retrieve blocks of text. There is only one kill buffer in emacs, which means that you can cut text from one document, and paste it into another.
To define a region of text, place the cursor at one end of the region and press Control-spacebar. That sets the mark. Then, move the cursor to the other end of the region. The text between the mark and the cursor defines the region.
To cut a region of text, and place it in the kill buffer, use the command Control-W (think of W ipe).
The paste command is Control-Y. It Y anks the block of text from the kill buffer, and places it where the cursor rests. The Control-Y command only retrieves the most recently-cut block of text.
You can paste in earlier cuts by pressing ESCAPE-Y. The ESCAPE-Y command, used repeatedly, will take you back through several previous text blocks that were cut. The ESCAPE-Y command does not work unless you type Control-Y first.
You may copy a region of text into the kill buffer without cutting it. Define the text block by setting the mark at one end, and moving the cursor to the other end. Then type ESCAPE-W.
Undoing changes
It is possible to undo the changes you have made to a file by entering the command Control-_. (That's Control-underscore. On some keyboards, you'll have to hold down both the control and shift keys to enter the underscore character.)
Many word processing programs can only undo the most recent command, but emacs remembers a long history of commands, allowing you to undo many changes by repeatedly entering the Control-_ code.