O'Reilly logo

Learning GNU Emacs, Second Edition by Eric S. Raymond, Bill Rosenblatt, Debra Cameron

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Rectangle Editing

When you mark regions to move or delete, they always cover the full width of the screen. Editing by region is fine for most of the work that you do in Emacs. But what if you wanted to edit a table? Since regions cover the full width of the screen, they can’t handle this case. 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, of adding or deleting comments accompanying code.

For example, let’s say you want to edit the following table, moving the “Working 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:

Rectangle Editing

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.

To define a rectangle, move the cursor to the upper-left corner and set the mark by pressing C-@ or C-SPACE, then move the cursor to the lower-right corner of the rectangle. Once you’re at the lower-right corner of the rectangle, move one character farther. Why move one character ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required