[CLUE-Tech] vi search/replace question

Keith Hellman khellman at mcprogramming.com
Fri Apr 23 07:27:03 MDT 2004


On Thu, Apr 22, 2004 at 10:54:50AM -0600, Dave Price wrote:
> 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.
Which is exactly what I would do (:%!grep -v '^#')...

But if your intent on doing it entirely in vi, try a macro recording in
command mode:
  q0/^s<ENTER>ddq10000 at 0
oh yes, and execute the above from the top line.  This saves a macro
into register 0 that 
- searches for your regex (/^s<ENTER>)
- erases the whole line if it is found
This macro is then executed 10000 times.  The first time it fails vim
aborts the macro playback, so you don't have to worry about removing
too many lines of your file.

Try
  :help record
for more info.

There may be a way to do it with regexp only, but I'm not familiar with
it.  HTH.

-- 
Keith Hellman                             #include <disclaimer.h>
khellman at mcprogramming.com                from disclaimer import standard
public key @ www.mcprogramming.com

"One World, one Web, one Program." - Microsoft(R) promotional ad
"Ein Volk, ein Reich, ein Fuhrer." - Adolf Hitler
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://cluedenver.org/pipermail/clue-tech/attachments/20040423/2919b68e/attachment.bin


More information about the clue-tech mailing list