Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete to start of pattern on another line?

I would like to know if it is possible to delete till the start of a pattern on another line.

p.e.

  1. good morning |
  2. empty line
  3. empty line
  4. empty line
  5. ....
  6. empty line
  7. hello world

Is it possible to delete from cursor "|" in line 1 till "world in line 7? (remaining in normal mode)

I do this often. Normally I use "dd" to delete all lines between line 1 and line 7 and then delete to word "dfw" but this is quit difficult if I'm on line 347 and my text is on 381. I have to count the lines between them and often I delete one line too much.

like image 253
Reman Avatar asked Mar 18 '11 16:03

Reman


2 Answers

Rather than using dd (which deletes a single line), you can use the more general d command as follows (^ is your cursor)

^The quick
 brown fox
 jumped over
 the lazy
 dog

Type d/the then press enter. It will delete from the cursor to the beginning of the first search match, leaving you with

 the lazy
 dog
like image 121
Jacob Avatar answered Oct 06 '22 09:10

Jacob


You can search for "world":

d/world<Enter>
like image 27
Felix Kling Avatar answered Oct 06 '22 09:10

Felix Kling