开发者

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? (remaini开发者_运维问答ng 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.


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


You can search for "world":

d/world<Enter>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜