In VIM how can I delete all lines until a regex is met?

Viewed 5068

I am sure this has been answered, but the query is a bit too complex for google.

In short, I am trying to delete many deprecated methods from some code. So I am skimming the file and when I see a method that I want to remove, I am deleting every line until I see a line that starts with a tab then the string "def".

I am thinking VIM should let me create a simple macro to do this, but the trick is escaping me.

Here is the kind of thing I want to remove.

def Method_to_Delete(self):
    """


    @return Control ID :
    @author
    """
    results = {}
    results['xx'] = "thingy"
    results['yy'] = 'thingy2'
    return results

def Method_to_Keep(self):
    """
     This is a method that does something wonderful!!!

    @return Control ID :
    @author
    """
    results = {}
    results['xxx'] = "WhooHoo!"
    results['yyy'] = 'yippee!!'
    return results

I want to have the cursor on the line with "def Method_to_Delete" and do something that will delete up until but not including "def Method_to_Keep"

There has got to be a better way than multiple "dd" commands.

2 Answers
Related