Vim - delete until it finds a pattern, but in the opposite direction

I know how to remove part of the text from the cursor position before the template appears, I mean d /<pattern> . I am wondering how to remove part of the text before the cursor position before the appearance of the template that is in front of the cursor position.

Be at position x in the file:

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

I want to delete

 >>>> aaaa ==== 

This works if the template exists only once in the file ... and vim has no choice. However, there is a problem with a file like this:

 >>>> aaaa ==== bbbb <<<< foo boo >>>> cccc ==== dddd <<<< 
+4
source share
2 answers

Can you search back using ? . Therefore, to delete back to the template, use d ?<pattern> .

+9
source

You can delete forward using f or t. For example, d2f_ would delete before and including the second underscore, and d2t_ would delete before, but excluding the second underscore. I just tried with gVim on a machine that ran you-know-something and works the other way around if you are capitalized f or t. Thus, d2F_ deletes BACK TO and includes the second-last underscore, and d2T_ will delete BACK TO, but excluding the second-last underscore.

I am so happy that I found it just to put pressure on the cheek glands.

+1
source

All Articles