Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting the first 'x' characters from every line in a region with Emacs

I want to delete the first x characters for every line in a region.

Is there any key binding available to do this without using regex?

like image 862
philg Avatar asked Apr 10 '13 15:04

philg


2 Answers

The best way to do this is to use the "rectangle" family of commands. For example, mark the beginning of the region. Go to the end of the region and place the point at column X. Run the command kill-rectangle using C-x r k.

Of course, this is not limited to deleting characters at the beginning of lines.

like image 191
Lindydancer Avatar answered Oct 23 '22 03:10

Lindydancer


If the mark is on column 0, put the point on column x and use kill-rectange:

C-x r k runs the command kill-rectangle, which is an interactive
autoloaded Lisp function in `rect.el'.

It is bound to C-x r k.

(kill-rectangle START END &optional FILL)

Delete the region-rectangle and save it as the last killed one.

When called from a program the rectangle's corners are START and END.
You might prefer to use `delete-extract-rectangle' from a program.
like image 39
stew Avatar answered Oct 23 '22 01:10

stew