How to remove several lines in the Vim editor using Regex

How to remove several lines in the Vim editor using Regex

A quick tip for those using the Vim editor: if you need to remove several lines that match your regular expression, just use the command:

:g /pattern/d

Example: If you want to remove the commented lines:

# this is a comment
def whatever
end

# this is another comment
def other_method
end

Just execute:

:g /^#.*/d

And then, your text will look like this:

def whatever
end

def other_method
end
Comments are closed.