Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim - delete until find a pattern, but in reverse direction

Tags:

vim

I know how to delete a part of text from cursor position to occurence of pattern, I mean d/<pattern>. I am wondering how to delete a part of text before cursor position until occurrence of pattern which is before cursor position.

Being in position x in file:

>>>>
aaaa
===x
bbbb
<<<<

I want to delete

>>>>
aaaa
====

This is work if pattern is exists only once in file... and vim doesn't have a choice. However there is a problem with file like this:

>>>>
aaaa
====
bbbb
<<<<

foo
boo

>>>>
cccc
====
dddd
<<<<
like image 755
noisy Avatar asked Dec 26 '22 05:12

noisy


1 Answers

You can search backwards using ?. So to delete back until a pattern, use d?<pattern>.

like image 168
Lars Kotthoff Avatar answered Dec 28 '22 17:12

Lars Kotthoff