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.
You can get the latest LogiPat.vim from
http://mysite.verizon.net/astronaut/vim/index.html#LOGIPAT
or a more stable version from:
http://vim.sourceforge.net/scripts/script.php?script_id=1290
Then you can do things such as
search for all lines that don't contain a pattern: :LogiPat !"some
string"
search for all lines that do contain two patterns: :LogiPat "one
thing" & "another thing"
search for all lines that have A and B but not C : :LogiPat "A" & "B"
& !"C"
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.
Regards,
Chip Campbell