In this section, learn some of the special commands and key bindings for editing text, most of which work regardless of the current major mode.
Regions can be automatically indented in different ways. The
indent-rigidly function, which you run by typing
C-x C-i, indents all lines in the region to the right
by one space.
C-Spaceto set the mark at the bottom of the buffer.
Move point to the beginning of the line that reads, "Little lamb, I'll tell thee," to mark the last 10 lines in the buffer as the region.
C-x C-ito indent the region one space.
C-x C-iagain to indent the region another space.
Just as you can run
indent-rigidly multiple times,
you can give a certain number of spaces to indent by preceding it with
C-u followed by a number; use a negative number to
move the region toward the left.
Indent the region by 10 more spaces: Type
C-u 10 C-x C-i.
Take the indentation back five spaces: Type
C-u -5 C-x C-i.
After this, your buffer should look like Figure 4.
Figure 4. Inserting rigid indentation
indent-rigidly function is also bound to the
To fill the region, justify the text with a ragged right margin and run
fill-region function. A similar function,
fill-paragraph, applies to the current paragraph. It
has a keyboard equivalent of
Try it: Type
M-x fill-region. Notice that once the
region is filled, point is moved to just after the region.
Like any of the Emacs formatting commands, the commands for indentation and
filling can be undone with the
undo function, which
was described in the first tutorial in this series. Try it once now to undo the
region fill: Type
Just as you can add or remove vertical space with indentations, you can also
take out any existing horizontal space. To do this, use the
M-\ (that's the Meta key followed by the \ key). It
removes all leading whitespace between the first nonspace character anywhere to
the left of point and the first nonspace character to the right of point, no
matter where point happens to be in the space.
Go ahead and try it. Take out all the leading spaces in the buffer by moving
point to the space on each line and typing
moving to the next line with spaces.
To add a line of vertical space, you can always press Enter, but doing
so also moves point. To add vertical space without moving point, run the
open-line function, which is bound to
Try it: Move down eight lines from the top of the buffer so that point is at
the beginning of the line reading "Little lamb, I'll tell thee," and type
C-o. Now your buffer should look like
Figure 5. Remove horizontal space and insert vertical space
Emacs has commands for transposition, which allow you to exchange the characters, words, or lines immediately after point with those immediately before point. These are good commands for making quick corrections in text.
transpose-chars function, to transpose the single
character before point and the single character after point; use
function, to transpose the single words before and after point.
Try it now:
Move point to the o in For and then type
C-tto transpose the o and F characters.
C-tagain to transpose the r and F characters.
Move point back to the F and type
C-tonce to move the F back one character.
Move point back to the F again and type
C-tonce more to move the F back to the beginning of the line.
M-tto transpose the words For and he.
M-tagain to transpose the words For and calls.
Move point between he and For and type
M-tagain to transpose them.
Move point between calls and For and type
M-tagain to transpose them.
M-tone last time to transpose calls and he.
C-x C-t, transposes the line at point and the line
Try it: Move point to the beginning of the line that begins "I a child" and
Note that you can also precede any of these commands with a numeric value by
using the universal argument,
C-u: C-u 2 C-x C-t
transposes the line at point with the line two lines ahead of point.
Another useful command,
the line at point with the previous line, separated by a space character. It's
M-^, which you type by pressing and holding
Meta and using the Shift key to type a caret (^). An alternate,
C-1 M-^, joins the current line with the line that
There are several Emacs functions for converting case. The
uppercase-word function (bound to
M-u) converts to uppercase letters of all the text
beginning from point forward to the end of the word. Similarly,
downcase-word (bound to
M-l) converts everything from point to the end of the
word to lowercase letters.
Try these on the buffer:
Move point to the line that begins with "For he calls" and type
M-c M-c M-l M-c M-l M-cso that the line is properly capitalized.
Move point down to the line that begins with "We are called" and type
M-u M-u M-u M-u M-u M-uso that the entire line is converted to uppercase letters.
C-ato move point to the beginning of the line and type
C-c C-l C-l C-l C-l C-c C-lso that the line is properly capitalized.
You can operate on words before point by preceding any of these commands
with the negative-argument function,
M--, which you
type by pressing and holding the Meta key and then pressing a hyphen character
(-). You can apply the case-changing commands to the region by using the
upcase-region functions, which are bound to
C-x C-l and
Table 3 lists the various text manipulation commands you've just learned and describes their meanings.
Table 3. Emacs text manipulation commands
|Binding||Command or function||Description|
||This command indents lines in the region (or at point).|
||This command fills all paragraphs in the region.|
||This command fills the single paragraph at point.|
||This command removes any horizontal space to the right and left of point.|
||This command opens a new line of vertical space below point, without moving point.|
||This command transposes the single characters to the right and left of point.|
||This command transposes the single words to the right and left of point.|
||This command transposes the line at point with the line before it.|
||This command joins the line at point with the previous line. Preface with
||This command converts the text at point to the end of the word to uppercase letters.|
||This command converts the text at point to the end of the word to lowercase letters.|
||This command converts the region to lowercase letters.|
||This command converts the region to uppercase letters.|