Wednesday, July 6, 2011

Re: Deleting duplicate lines _without_ sorting

Hi Karol,

2011/7/6 Karol Samborski <edv.karol@gmail.com>
Hi Stefan,

I would do simple macro like this one (before starting recording macro
place cursor on the first column of the first line you want to check):
qa -- start recording macro 'a'
y$ -- copy whole line
j -- place the cursor one line down
:,$g/ -- we want to delete every duplicate of copied line to the end
of file so we do the global command
<C-r>" -- this should paste the copied line
/d<CR> -- and tell vim to delete these duplicate lines, <CR> means
that you should press enter
<C-o> -- place cursor back to the last place (the line below the
checked line recently)
q -- stop recording

and then 999@a should remove all duplicate lines.

I tested it on simple file but I don't say this will be always
correct. Just try it.

Thank you, i didn't thought of using global from current position to the end, this realy does the trick.
Since i can identify the duplicate lines by a regexp and the dups aren't nested i used a search instead of <C-o>.

regards,
Stefan

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