On Thursday, January 23, 2014 8:51:16 AM UTC-6, 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 : 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.
>
I'd approach this as "on every line containing arch, delete the line if it does
not contain sparc". This can be done as follows:
:g#arch#if getline('.')!~'sparc' | d | endif
Note I used !~ for a regular expression match which respects the 'ignorecase'
setting. I think this is appropriate here since you are doing this
interactively; if you were writing a plugin or you need strict case sensitivity
(or insensitivity) then you should use !~# or !~?.
--
--
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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment