Charles E Campbell Jr wrote:

jas01 wrote:

I have a huge file where I need to delete all lines except for a few I need.
I'm trying to do this in a single command.

I know that:

:v/Text/d
will delete all lines except for ones containing 'Text.' I have no idea how to put multiple strings so the command deletes everything except for 'Text'
and 'Text2' and 'Text3'.

:v/Text[23]\=/d

I rather expect that that answer won't be adequate, though. If you want to construct regexp's that
handle boolean logic requirements, I suggest looking into LogiPat.

So, to do what you're asking, and assuming that you're not literally looking for "Text...":

 :echo LogiPat('"Text" & "Text2" & "Text3")

which yields:    \%(.*Text.*\&\%(.*Text2.*\&.*Text3.*\)\)

so  :v/\%(.*Text.*\&\%(.*Text2.*\&.*Text3.*\)\)/d

will delete all lines that don't have Text, Text2, or Text3 in them.

Whoops -- sorry, that command will delete all lines that don't have Text, Text2 AND Text3 in them.

Try :echo LogiPat("Text" | "Text2" | "Text3")
which yields:  \%(.*Text.*\|\%(.*Text2.*\|.*Text3.*\)\)
so :v/\%(.*Text.*\|\%(.*Text2.*\|.*Text3.*\)\)/d

will do what you want. Now, LogiPat doesn't guarantee that you'll get the smallest possible regexp
to do the job you want.  A smaller one would be:

:v/Text\|Text2\|Text3/d

You'll note that LogiPat has \%(...\) and .* in its pattern which facilitates the use of additional logic.

Regards,
Chip Campbell

Reply via email to