Marking Text to Delete, Move, or Copy

What if the text you want to delete is just a phrase? Or half a paragraph? Or several paragraphs? You could use the various delete commands in combination to delete just the part you want to, but Emacs offers an easier way: defining the area you want to delete by marking text. The marked area is called a region.

To define a region, you use a secondary pointer called a mark. Some versions of Emacs display the mark on the screen; unfortunately, in GNU Emacs, the mark is invisible.

You set the mark at one end of the region by pressing C-@ or C-SPACE, then move the cursor to the other end of the region. (The cursor is sometimes also referred to as point. There is one minor but important difference between the cursor and the point, however. The cursor is on top of a character; in Emacs, the point is actually in between the character the cursor is on and the previous character. As we said, this difference is minor, but it helps you to visualize where the cursor should be when you mark a region.) Figure 2-4 illustrates point, mark, and region.

Point, mark, and region

Figure 3-4. Point, mark, and region

Let’s mark a sample region. In this example, we remove the phrase “it was the worst of times.” First, we find the beginning of the phrase. Then we set the mark, move forward to the end of the phrase, and delete. We use shading to indicate the region that is selected (you won’t ...

Get Learning GNU Emacs, Second 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.