Rectangle Editing

When you mark regions to move or delete, they always cover the full width of the window. Editing by region is fine for most of the work that you do in Emacs. But what if you wanted to edit a table? Regions cover the full width of the window, so they can't handle columns. Emacs offers another way to define areas to delete, copy, and move around: using rectangles. Rectangles are just what they sound like: rectangular areas that you define and manipulate using special rectangle editing commands. Editing with rectangles is useful whenever you want to move or delete vertical columns of information; for instance, moving a column of a table or rearranging fields in a dataset.

For example, let's say you want to edit the following table, moving the "Hours" column to the right side. There's no way to do this using regions, but it's easy to do if you learn some rectangle editing commands.

Initial state:

image with no caption

A flextime schedule.

You define a rectangle the same way you define a region; the commands you use after marking the area tell Emacs whether you want to work with a region or a rectangle. (This is a good time to let go of your mouse and use keyboard commands for marking the text. Highlighting remains horizontal when you're working with rectangles and will only confuse you as you begin to think rectangularly. Of course, there's nothing wrong with using the mouse to move ...

Get Learning GNU Emacs, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.