Now that you know how to enter and exit Emacs as well as the basics of working with files, it's time to learn how to move around in and edit files. Emacs offers lots of ways to move around in files. At first, you might find it confusing that there are so many ways to do the same thing. Be patient as you learn, the confusion will lessen, and you'll begin to appreciate the variety of Emacs commands. The more ways you learn, the fewer keystrokes you'll need to get to the part of the file you want to edit. If you want to practice commands while you're reading which will help you learn faster start by typing a page or two from anything you happen to have handy; the newspaper is fine. That will give you some text to work with as you learn the editing skills described in this chapter. Don't worry if you make mistakes; just keep on typing. You can correct any mistakes after you learn the basic editing skills outlined here. Learning any editor is primarily a matter of forming certain finger habits rather than memorizing what the book says. You will learn the right finger habits only if you start typing. When you are typing and you get to the right side of the display, you have two options. You can press Enter to go to the next line, or you can keep typing. If you type a long line and don't press Enter, Emacs waits until you reach the end of the display. Then it puts a curved arrow at the end of the line and one at the beginning of the next line as a visual indication that the next line is a continuation of the previous line (see Figure 2-1). If Emacs is run in a nongraphical environment, a backslash (\) is used instead. Figure 2-1. Graphical versions of Emacs use curved arrows to indicate that a line is continued; terminal versions use backslashesRefill mode is a minor mode that keeps paragraphs neat as you edit them. It is not on by default. Look at the mode line. If the word Refill appears, you are in refill mode already. If not, you can turn it on for this buffer only by typing M-x refill-mode Enter. If you decide that you don't like refill mode, type M-x refill-mode Enter again. This command is like a light switch: it toggles refill mode on and off. You may decide that you want to enter refill mode automatically whenever you edit. We'll describe how to do so at the end of this chapter. In some contexts, refill mode can be annoying, and it is still a work in progress according to the Emacs manual. You may prefer auto-fill mode. You enter it in the same way; type M-x auto-fill-mode Enter. The word Fill appears on the mode line. When you type paragraphs, auto-fill mode formats them. When you edit them, however, auto-fill mode does not automatically reformat them. You do that yourself using the fill-paragraph command, M-q. If you turn on refill mode and then decide to use auto-fill mode, you still have to turn refill mode off explicitly by typing M-x refill-mode Enter. Otherwise, both modes appear on the mode line, and refill mode continues its merry automatic reformatting of paragraphs, ignoring the fact that auto-fill mode has been enabled. Watch out for one important pitfall when reformatting paragraphs. In text mode, a paragraph is any text that is indented or has a blank line before and after it. If you have a file with no blank lines, Emacs thinks it is all one long paragraph. Typing M-q takes all the text, ignoring line breaks, and makes it one long paragraph. This command is a particular problem if you have a data file, a program, or if you just prefer to write files with no blank lines. Luckily, pressing C-_ or C-x u (both for undo) magically puts things back the way they were. If you regularly create files with no blank lines, here are some suggestions:
Table 2-1 lists commands for filling text automatically and reformatting paragraphs with auto-fill mode.
|