Thursday, January 23, 2014

Re: how to delete lines containing a pattern and not containing another pattern?

On 2014-01-23 14:51, 김찬 wrote:
> I'm a long-time vi(m) user and I have question.
> Can I remove lines that contain a pattern but not another pattern?
> For example,
>
> Line 1 : rabbit
> Line 2 : arch sparc
> Line 3 : arch arm
> Line 4 : tiger
> I want to remove lines containing arch but not containing sparc.
> So Here I want to remove only line 3 leaving lines 1, 3 and 4
> intact.

Dr. Chip's LogiPat plugin[1] makes quick work of generating such
patterns. I did

:echo LogiPat('"arch"&!"sparc"')

and it gives me the pattern

\%(.*arch.*\&^\%(\%(sparc\)\@!.\)*$\)

which I can then use in a :g/pattern/d command:

:g/\%(.*arch.*\&^\%(\%(sparc\)\@!.\)*$\)/d



[1] http://www.vim.org/scripts/script.php?script_id=1290

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: