Tuesday, October 9, 2012

Re: How to "destructive vimdiff" ;) two files ?

On Sun, October 7, 2012 04:50, meino.cramer@gmx.de wrote:
> Hi,
>
> There are two files ("A" and "B") - both sorted alphabetically and of
> comparable
> contents.
>
> "A" is missing some entries of "B" and "B" is missing some entries of
> "A".
>
> I want to delete all entries both files have in common.
>
> Is this possible with vim in a easy way?
>
> Thank you very much in advance for any help!

The best way would involve using comm, as Gary suggested. But here is a
way to do it in Vim:

You need to loop over each line and get the diff_hlID() for that position.
Each line, where diff_hlID() returns zero you need to delete.

Of course, you can do it in one step ;)

exe ':g/'. join(map(filter(range(1,line('$')), '!diff_hlID(v:val, 0)'), '
''\%''.v:val."l"'), '\|'). '/d'

But, this works only once, you can't do this for all buffers at the
same time, since after you changed the first buffer the syntax highlighting
for the other will be completely different and there will be no more
items being in common at the following buffers.


regards,
Christian

--
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

No comments:

Post a Comment