8

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?

0

3 Answers 3

18

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.

16

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
  • 1
    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
    Nov 25, 2021 at 18:36
  • 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
    Nov 26, 2021 at 20:57
0

If you use evil, I've found evil-visual-block bound to C-v to be the most straightforward.

  • C-v to enter visual block mode
  • Arrows (or preferred movement) to select column/rectangular region
  • d delete

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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