On Friday, January 24, 2014 4:02:05 AM UTC-8, Chan Kim wrote:
> On Thursday, January 23, 2014 11:51:16 PM UTC+9, Chan Kim 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 : rabbitLine 2 : arch sparcLine 3 : arch armLine 4 : tigerI 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. I can remove lines containg 'arch' by:g/arch/dI can remove lines not containing 'sparc' by:g!/sparc/dHow do I combine those two?I tried:g/arch/&!/sparc/d or :g/arch&!sparc/dBut of course it doesn't work. (with escape before ! also)Is there a way to remove only line 3? I looked it up in the manual but in vain..Thank you!
>
> -------------
>
> Thank you Tim and Ben (I'll read Ben's post later..)
>
> But I found maybe the nicest one. The following line does it.
>
> :v /sparc/s/.*arch.*\n//
>
Careful with line deleting substitutions when using :g/:v. It will not work always:
For eg. with a file like this
--
Line 2 : arch sparc asd
Line 3 : arch arm
Line 4 : arch aaa
---
..the "arch aaa" will not be deleted.
Tim's & Ben's method would do it.
One more way to do this is:
:g/.*arch\&.*\(sparc.*\)\@<!$/d
--Arun
--
--
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:
Post a Comment