The mark and the mouse
You're well on your way to grasping all the basics of Emacs editing, but there are a few more important concepts to learn: how to mark sections of text and perform operations on them and how to use the mouse.
Emacs has a facility for marking an area of text so that you can edit it as a whole. These commands are described here and outlined in Table 5.
Move to the top of the buffer -- the beginning of the first stanza -- and type
C-Space by pressing and holding Ctrl and then pressing the spacebar. This is called setting the mark; a message in the minibuffer tells you that the mark has been set.
Everything between point and the place where you've set the mark is called the region.
Make the whole first stanza the region by moving point down to the blank line right after the stanza.
There are special commands that work on the region, including
C-w, which kills it.
C-w to kill the region you just defined.
Whenever you kill text, it's saved in the Emacs kill ring. You can get it back by yanking it at point with
C-y. Move to the end of the buffer, press Enter to insert another blank line, and then yank the stanza back.
You're not limited to killing regions; use
C-k to kill all the text from point to the end of the line. Move up to the line beginning with Tiger, and kill it with a
C-k. Notice that doing so doesn't take out the blank line; that requires a second
C-k. Do it, and then use
C-y to yank the whole line back. If you kill with multiple kill commands typed in succession, they're added together, and a single yank returns them.
You can yank a line as many times as you want. Move to the top of the buffer, and yank the line back again with another
You can also kill multiple lines with successive
C-k keystrokes, and they're yanked together. Try killing several lines at once, and then yank them right back as they were with a single
You don't have to kill the region in order to copy it. To save the region in the kill ring without killing it, use
M-w instead of
- Move point to the beginning of the second line of the bottom stanza.
C-Spaceto set the mark.
- Move point to the line beneath the stanza.
M-wto copy these three lines in the kill ring without killing them.
- Move point up to the blank line beneath the first line in the buffer.
- Yank the three lines with
After this, your buffer should look like Figure 8.
Figure 8. Yanking multiple lines
Table 5. Emacs functions for marking and killing text
||Set the mark at point.|
||Kill all text from point to the end of the line.|
||Kill the region.|
||Save the region in the kill ring, but don't kill it.|
||Yank text from the kill ring.|
Although Emacs is designed for fast keyboard use, you can use the mouse -- and doing so sometimes comes in handy in text operations.
To move point anywhere in the buffer, move the mouse pointer to where you want to go, and click the first mouse button once. Try using the mouse to move to the space between the second and third stanzas, and type a new stanza:
When the stars threw down their spears, And watered heaven with their tears, Did he smile his work to see? Did he who made the Tiger make thee?
Double-clicking a word with the first button selects that word. Double-click the Tiger you just typed -- it should become highlighted -- and press Del to delete it. Now type
Lamb to insert that word at point.
To select a whole line with the mouse, triple-click the line with the first mouse button. Try it on the top line, and press Del to delete it. Type
C-_ to bring it back.
Click the first button in the middle of the buffer, and type two more paragraphs to complete the poem:
What the hammer? what the chain? In what furnace was thy brain? What the anvil? what dread grasp Dare its deadly terrors clasp? And what shoulder, and what art, Could twist the sinews of thy heart? And when thy heart began to beat, What dread hand? and what dread feet?
You can click the first mouse button and drag the pointer to select a region. You can also select a region by clicking the first button once (which sets point there) and then clicking the third button somewhere else (which sets the mark there). When you do that, the text you've selected is placed in the kill ring without killing it -- you can use
C-y or the middle mouse button to yank the text at point. To place the highlighted region in the kill buffer and kill it, double-click with the third mouse to set the region.
Try switching the order of the two stanzas you just typed:
- Click the first mouse button on the beginning of the blank line between them.
- Double-click the third mouse button below the second stanza you just typed.
- Click the second mouse button at the beginning of the blank line before the stanza that begins with What the hammer?
C-x C-s to save your buffer to disk. Your Emacs session should now look like Figure 9.
Figure 9. Inserting with the mouse
Table 6 describes the various Emacs mouse operations.
Table 6. Mouse operations in Emacs
||This command sets the point; drag B1 to set the region.|
||This command marks a word.|
||This command marks a line.|
||This command yanks the text.|
||This command sets and highlights the region, and then places it in the kill buffer without killing it. If a region is already highlighted and set, the end of the region moves to the place where you click.|
||This command sets and highlights the region and then kills it. If a region is already highlighted and set, the end of the region moves to the place where you click, and then the region is killed.|