Rectangle commands operate on rectangular areas of the text: all the characters between a certain pair of columns, in a certain range of lines. Emacs has commands to kill rectangles, yank killed rectangles, clear them out, fill them with blanks or text, or delete them. Rectangle commands are useful with text in multicolumn formats, and for changing text into or out of such formats.
When you must specify a rectangle for a command to work on, you do it by putting the mark at one corner and point at the opposite corner. The rectangle thus specified is called the region-rectangle because you control it in much the same way as the region is controlled. But remember that a given combination of point and mark values can be interpreted either as a region or as a rectangle, depending on the command that uses them.
If point and the mark are in the same column, the rectangle they delimit is empty. If they are in the same line, the rectangle is one line high. This asymmetry between lines and columns comes about because point (and likewise the mark) is between two columns, but within a line.
Command of rectangles
- or M-x kill-rectangle
Kill the text of the region-rectangle, saving its contents as the “last killed rectangle”.
- or M-x delete-rectangle
Delete the text of the region-rectangle.
- or M-x yank-rectangle
Yank the last killed rectangle with its upper left corner at point.
- or M-x open-rectangle
Insert blank space to fill the space of the region-rectangle. This pushes the previous contents of the region-rectangle rightward.
- or M-x clear-rectangle
Clear the region-rectangle by replacing all of its contents with spaces. M-x delete-whitespace-rectangle Delete whitespace in each of the lines on the specified rectangle, starting from the left edge column of the rectangle.
- <span title="Try `C-h k C-x r t string <RET>' for more information." style="border-bottom:1px dotted">[C-x r t string <RET>]</span> or M-x string-rectangle
Replace rectangle contents with string on each line.
- M-x string-insert-rectangle <RET> string <RET>
Insert string on each line of the rectangle.