Tuesday, August 25, 2009

Re: Remove everything up to and including a certain word

On Aug 24, 6:24 pm, Derek Wyatt <ewipla...@gmail.com> wrote:
> On Mon, Aug 24, 2009 at 7:06 PM, Gary Johnson <garyj...@spocom.com> wrote:
> >     :%s/\_.*hello word//
>
> > See
>
> >    :help /\_.
>
> Gary takes the prize.  However, if you're "interactive" and you happen to be
> on the spot you want to delete from, you could also do this:
>
>     d/hello word\zs
>

Actually, I like ggd/hello word/e better.

gg - go to beginning of the file
d/hello word/e - delete from current cursor position to the END of the
match (because of "/e") for "hello word"

I believe that the regex with \_.* in it will take much longer because
it will involve backtracking, since regular expressions are greedy.

If you're determined to do it with regex, this would probably be
faster:

:%s#\%^\_.\{-}hello word##

\%^ - start of file
\_.\{-} - AS FEW AS POSSIBLE of any character, including line endings
hello word - desired keyword text

See :help \%^ for an example of usage to find the first occurrence of
a keyword in a file.

But, that's getting to be a LOT more complex than the simple methods
using d/ that have already been discussed.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

No comments: