4

I have this text

1 A
2 B
3 C

I want to remove the first column to make it

A
B
C

Ok so I need to make a rectangle. Reading about rectangles I see

"To specify a rectangle for a command to work on, set the mark at one corner and point at the opposite corner. The rectangle thus specified is called the region-rectangle. If point and the mark are in the same column, the region-rectangle is empty. If they are in the same line, the region-rectangle is one line high."

I go to line 1 column 1 and set the mark with C-SPC. I go to the end of the rectangle at line 3 column 2 (to include column 1 only). Then I do C-w. It kills everything up to C:

 C

Obviously it included columns 2 and 3. How to prevent this and only select column 1?

New contributor
BigBoy1337 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
0
13

C-w kills the text between point and mark; it’s the normal command you would use to kill text. C-x r k kills the rectangle between point and mark. This is the one you want to use.

11

If you select the rectangle, which in Emacs terms means make it an active rectangular region, then C-w does just what you expect.

Use C-x SPC to activate a rectangular region that you want to kill. Then just use C-w, the usual key for killing the active region.

To select a rectangular region, do one of the following:

  • Put point and mark at opposite corners (the same thing you'd need to do to be able to use C-x r k) and then hit C-x SPC.

  • Use C-x SPC first (that activates an empty rectangular region), and then move point to the opposite corner, extending the selection as you move the cursor.

  • Drag C-M-mouse-1 to select the rectangle. (Thanks to @pst for pointing this out in a comment here.) For this, you need Emacs 27 or later.

2
  • Or, select that rectangular region by pressing Ctrl + Meta while selecting with mouse-1. Then use normal C-w (or DEL) for killing the region. (Question didn't say "... from the keyboard", so I think it's good to mention this way as well.)
    – pst
    yesterday
  • 1
    @pst: Good point. I've added that to the answer. If you prefer, you can post it separately as an answer and I'll remove if from this answer. Thx.
    – Drew
    15 hours ago

Your Answer

BigBoy1337 is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.