[CLUE-Tech] vi search/replace question

Todd Williams hp205ctl at hotpop.com
Fri Apr 23 11:28:43 MDT 2004


:1,$g/^#/d

replace the '^#' with your real regex

It says, more or less "from line one to the end, globally search for /^#/ and delete line when found"

That is an old "ex" command - vim is "vi improved", vi was built upon ex which was built upon ed, and all the old line editing commands are still available, and sometimes quite useful.

Todd

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'?
> 
> I know I could do this easily by piping the file out to grep -i, but
> lets just say I don't have a good grep available under this OS.... Or I
> just want to learn to do this entirely in vi.
> 
> Of course, if it can be done with one command in (horrors) emacs, I
> would be interested in learning how.
> 
> Thanks, and
> 
> aloha (textually),
> dave
> 
> _______________________________________________
> CLUE-Tech mailing list
> Post messages to: CLUE-Tech at clue.denver.co.us
> Unsubscribe or manage your options: http://clue.denver.co.us/mailman/listinfo/clue-tech
> 






More information about the clue-tech mailing list