Sams Teach Yourself Emacs in 24 Hours

ContentsIndex

Hour 12: Visible Editing Utilities

Previous HourNext Hour

Sections in this Hour:

 

Rectangular Commands

In Hour 4, you saw how to cut and paste characters from one location in the buffer to another point (a region). In certain situations, you are not interested in cutting and pasting from one point or character to another, but rather using rectangles. An example of this can be seen in Figure 12.11, where you want to remove the initial characters of each line. These lines are from the file pager.el, where the given lines are inserted into the .emacs file. They have, however, the Lisp comment characters in front of them, which you need to remove.

Figure 12.11
Example of a rectangle.

To remove this rectangle, place point at one end of the rectangle, and the mark at the other end (as can be seen in Figure 12.11), and press C-x r k (kill-rectangle). This is easy to remember, in fact: C-x is the prefix for most complex commands, r for rectangle, and k for kill.

Besides killing a rectangle you can also paste it back in another location. This is done by pressing C-x r y (yank-rectangle). The upper-left corner of the rectangle is anchored at the place where point was located when C-x r y was invoked and space is made for the rectangle in all affected lines. Although this is a silly example, it can be seen in Figure 12.12 where the rectangle killed in Figure 12.11 was just pasted in.

Figure 12.12
A rectangle is pasted in using C-x r y (yank-rectangle).

Finally, it is possible to insert a text string at the left side of each line that the rectangle spans. This is done by pressing C-x r t (string-rectangle), when a rectangle has been defined. Emacs asks for the text to insert in the minibuffer; when you type it and press Enter, the text is inserted.

Sams Teach Yourself Emacs in 24 Hours

ContentsIndex

Hour 12: Visible Editing Utilities

Previous HourNext Hour

Sections in this Hour: