[CLUE-Tech] vi search/replace question

Mike lister-clue at gantsfort.com
Fri Apr 23 08:48:44 MDT 2004


On Thu, Apr 22, 2004 at 10:54:50AM -0600, Dave Price wrote:
> Hello,
> 
> This one comes up too often for me, and I don't know if there is an easy
> way to do it just with vi/vim:
> 
> Is there a way to delete entire lines globbally from a file when part
> of the line matches a pattern?
> 
> For example, I want to remove all the lines the start with a particular
> character, perhaps #, (so the regex to find the lines would be ^# ...
> 
> How can I tell vi to replace the regex and the rest of the line with
> 'nothing'?

Maybe something like this:

:g/^#/d

Explanation:
colon(:), enter ex mode
g, for global (entire file)
/^#/, regular expression
d, delete lines that match the RE

HTH,
Mike



More information about the clue-tech mailing list