You can also transpose two words, lines, paragraphs, or sentences. To transpose two words, put the cursor between the two words and press M-t. After Emacs has finished, the cursor follows the second of the two (transposed) words:
Before M-t |
After M-t |
one three _ two |
one two three _ |
Interestingly, Emacs moves words, but not punctuation. Let's say that two names are reversed:
Before M-t |
After M-t |
Charles, Dickens |
Dickens, Charles _ |
To transpose two lines, put the cursor anywhere on the second of the two and press C-x C-t. Emacs moves the second before the first:
Before C-x C-t |
After C-x C-t |
second line |
first line |
first line |
second line |
third line |
third line |
Table 2-9summarizes the transposition commands.
Table 2-9. Transposition commands
Keystrokes |
Command name |
Action |
C-t |
transpose-chars |
Transpose two letters. |
M-t |
transpose-words |
Transpose two words. |
C-x C-t |
transpose-lines |
Transpose two lines. |
( none ) |
transpose-sentences |
Transpose two sentences. |
( none ) |
transpose-paragraphs |
Transpose two paragraphs. |
2.5.2 Changing Capitalization
Mistakes in capitalization are also common and annoying typing errors. Emacs has some special commands for fixing capitalization. To capitalize the first letter of any word, put the cursor on the first letter and press M-c. To put a word in lowercase, press M-l. To put a word in uppercase, press M-u. The key bindings here are mnemonic: Metafollowed by cfor capitalize, lfor lowercase, and ufor uppercase. Note that if the cursor is in the middle of a word, Emacs takes action only from the character under the cursor to the end of the word. You can easily use M-lto lowercase the second half of a word, and so on.
If you notice that the word you just typed is incorrect, you can use the same commands prefaced by Meta-(press and hold Metafollowed by a hyphen). This corrects the previous word without moving the cursor. If the cursor is positioned in the middle of a word, using Meta-before a command causes it to work on the first part of the word (the part preceding the cursor), rather than the part following the cursor.
For example, starting with abcd efghij
:
If you press: |
You'll get: |
Meta - u |
abcdEFGHIJ _ |
Meta - M-u |
ABCD efghij |
M-c |
abcdEfghij _ |
Meta - M-c |
Abcd efghij |
Table 2-10summarizes the capitalization commands.
Table 2-10. Capitalization commands
Keystrokes |
Command name |
Action |
M-c |
capitalize-word |
Capitalize first letter of word. |
M-u |
upcase-word |
Uppercase word. |
M-l |
downcase-word |
Lowercase word. |
Meta - M-c |
negative-argument; capitalize-word |
Capitalize previous word. |
Meta - M-u |
negative-argument; upcase-word |
Uppercase previous word. |
Meta - M-l |
negative-argument; downcase-word |
Lowercase previous word. |
You may be used to typing over old text rather than having to delete it. There is a certain satisfaction in destroying some really bad text in this way. You can do this in Emacs, too, by entering a minor mode called overwrite mode. When you're in overwrite mode, any new text you type wipes out the text that's underneath. When you're not in overwrite mode (i.e., in normal Emacs), any new text you type is inserted at the cursor position and any subsequent text is pushed to the right. (Other software may refer to this as insert mode; because it is the way GNU Emacs normally behaves, it doesn't have a name here.)
To enter overwrite mode, press the Insertkey. [15] Ovwrtshould appear on the mode line. If this doesn't work (or if you don't have an Insertkey), type M-x overwrite-mode Enter. You can turn off overwrite mode by typing M-x overwrite-mode Enteragain. Using Emacs's command completion, simply type M-x ovand press Enter. This is enough of a unique string to tell Emacs you want to toggle overwrite mode. Completion, one of the best shortcuts in Emacs, is discussed further in Chapter 14 Chapter 14. The Help System Emacs has the most comprehensive help facility of any text editor—and one of the best such facilities of any program at all. In fact, the Emacs help facilities probably cut down the time it took for us to write this book by an order of magnitude, and they can help you immeasurably in your ongoing quest to learn more about Emacs. In this chapter, we describe Emacs help in the following areas: • The tutorial. • The help key ( C-h ) and Help menu, which allow you to get help on a wide variety of topics. • The help facilities of complex commands like query-replace and dired . • Navigating Emacs manuals and using the info documentation reader. • Completion , in which Emacs helps you finish typing names of functions, variables, filenames, and more. Completion not only saves you time and helps you complete names of functions you know about but can help you discover new commands and variables.
.
2.6 Canceling Commands and Undoing Changes
Sometimes you start a command by accident or change your mind about it. Don't worry: with Emacs, you can quit in the middle or undo it.
When you want to cancel any command that's in progress, press C-g. The word Quitappears in the command area. This command is helpful when you are stuck in the minibuffer and didn't really mean to go there. Depending on what you were doing, you may have to press C-ga few times.
What happens if you make a mistake while you're editing? You can undo your changes by pressing C-_or C-x u(for undo; conveniently, the toolbar also has an undo icon, a curved left arrow). By typing undorepeatedly, you can gradually work your way back to a point before your mistake. [16]Although the undocommand is very powerful, saving your file frequently, if not compulsively, is nevertheless a good idea. We usually save a file whenever we stop typing—even if only for a few seconds. Train your fingers to press C-x C-swhenever you pause; it's a good habit to form.
Читать дальше