Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim: replace a line pattern by a no line

Tags:

regex

vim

I'm trying to achieve a simple substitution on vim but can't get it right. I need to remove, on an entire file, all the lines that match a pattern. The pattern is "something*", meaning "something" followed by anything until the end of the line. I tried :%s/pattern*\n//g and :%s/pattern*$//gwithout success. Any ideas?

Cheers!

like image 576
brafales Avatar asked May 05 '11 08:05

brafales


1 Answers

Use :g instead of :substitute.

:g/pattern/d

would remove all the lines that match with pattern.

As for the pattern, yours will match patter, pattern, patternn and so on. Use the wildcard . to match any characters. So your regexp should be pattern.*$ --- but if you wish to remove the lines entirely, the :g/pattern/d does the trick fine.

like image 197
mike3996 Avatar answered Sep 23 '22 03:09

mike3996