Reputation: 6823
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
<<<<
Upvotes: 4
Views: 1324
Reputation: 11
One can delete ahead using f or t. For example d2f_ would delete up to and including the second underscore, and d2t_ would delete up to but excluding the second underscore. I just tried with gVim on a machine running you-know-what and it works in reverse if you capitalise the f or t. So d2F_ would delete BACK TO and including the second-to-last underscore and d2T_ would delete BACK TO but excluding the second-to-last underscore.
I'm so happy to have found this that I could just press my cheek glands.
Upvotes: 1
Reputation: 109272
You can search backwards using ?
. So to delete back until a pattern, use d?<pattern>
.
Upvotes: 9