The rectangle commands affect rectangular areas of text: all characters between a certain pair of columns, in a certain range of lines. Commands are provided to kill rectangles, yank killed rectangles, clear them out, or delete them. Rectangle commands are useful with text in multicolumnar formats, like code with comments at the right, or for changing text into or out of such formats.
To specify the rectangle a command should work on, put the mark at one corner and point at the opposite corner. The specified rectangle is called the region-rectangle because it is controlled about the same way the region is controlled. Remember that a given combination of point and mark values can be interpreted either as specifying a region or as specifying a rectangle; it is up to the command that uses them to choose the interpretation.
Delete the text of the region-rectangle, moving any following text on each line leftward to the left edge of the region-rectangle.
Similar, but also save the contents of the region-rectangle as the “last killed rectangle”.
Yank the last killed rectangle with its upper left corner at point.
Insert blank space to fill the space of the region-rectangle. The previous contents of the region-rectangle are pushed rightward.
Clear the region-rectangle by replacing its contents with spaces.
The rectangle operations fall into two classes: commands deleting and moving rectangles, and commands for blank rectangles.
There are two ways to get rid of the text in a rectangle: you can discard the text (delete it) or save it as the “last killed” rectangle. The commands for these two ways are M-x delete-rectangle and M-x kill-rectangle. In either case, the portion of each line that falls inside the rectangle’s boundaries is deleted, causing following text (if any) on the line to move left.
Note that “killing” a rectangle is not killing in the usual sense; the rectangle is not stored in the kill ring, but in a special place that only records the most recently killed rectangle (that is, does not append to a killed rectangle). Different yank commands have to be used and only one rectangle is stored, because yanking a rectangle is quite different from yanking linear text and yank-popping commands are difficult to make sense of.
Inserting a rectangle is the opposite of deleting one. You specify where to put the upper left corner by putting point there. The rectangle’s first line is inserted at point, the rectangle’s second line is inserted at a point one line vertically down, and so on. The number of lines affected is determined by the height of the saved rectangle.
To insert the last killed rectangle, type M-x yank-rectangle. This can be used to convert single-column lists into double-column lists; kill the second half of the list as a rectangle and then yank it beside the first line of the list.
There are two commands for working with blank rectangles: M-x clear-rectangle erases existing text, and M-x open-rectangle inserts a blank rectangle. Clearing a rectangle is equivalent to deleting it and then inserting a blank rectangle of the same size.
Rectangles can also be copied into and out of registers. See Rectangle Registers.