Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs: How to delete a line starting with specific text

How can I find and delete lines which start with the text in?

I use the command C-M-s ^in to find all lines starting with in, but then I don't really know what to do.

like image 765
MAXIME MLINARIC Avatar asked Nov 29 '17 21:11

MAXIME MLINARIC


People also ask

How do I delete a specific line in Emacs?

Move your cursor directly before the region you want to delete. Set a mark by pressing Ctrl-6 or Ctrl-^ . Move the cursor to the end of the region you want to delete and press Ctrl-k .

How do I delete a specific line?

Delete lines or connectorsClick the line, connector, or shape that you want to delete, and then press Delete. Tip: If you want to delete multiple lines or connectors, select the first line, press and hold Ctrl while you select the other lines, and then press Delete.

How do you delete text in Emacs?

Emacs provides many ways to delete text. The simplest way to delete text is to press the DEL key, which deletes the character immediately to the left of the cursor. See Figure 2-3 for possible locations of the DEL key on your keyboard. DEL is easiest to define by what it does: it deletes the previous character.


2 Answers

M-x flush-lines RET ^in RET

C-h f flush-lines tells you:

flush-lines is an interactive compiled Lisp function in replace.el.

It is bound to menu-bar edit flush-lines.

(flush-lines REGEXP &optional RSTART REND INTERACTIVE)

Delete lines containing matches for REGEXP.

When called from Lisp (and usually when called interactively as well, see below), applies to the part of the buffer after point. The line point is in is deleted if and only if it contains a match for regexp starting after point.

If REGEXP contains upper case characters (excluding those preceded by \) and search-upper-case is non-nil, the matching is case-sensitive.

Second and third arg RSTART and REND specify the region to operate on. Lines partially contained in this region are deleted if and only if they contain a match entirely contained in it.

Interactively, in Transient Mark mode when the mark is active, operate on the contents of the region. Otherwise, operate from point to the end of (the accessible portion of) the buffer. When calling this function from Lisp, you can pretend that it was called interactively by passing a non-nil INTERACTIVE argument.

If a match is split across lines, all the lines it lies in are deleted. They are deleted before looking for the next match. Hence, a match starting on the same line at which another match ended is ignored.

like image 152
Drew Avatar answered Sep 28 '22 00:09

Drew


query-replace-regexp "in.*" to "" will be work. you should not input " to the prompt

like image 39
carlos Avatar answered Sep 28 '22 00:09

carlos