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.
Best Regards,
Karol Samborski
2011/7/6 Stefan Klein <st.fa...@googlemail.com>:
> --
> 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
>
well, maybe, but probably not as fast since its processing time would be
on the order of the square of the number of lines: simply write a
function with a double loop, which would examine all lines 1→$ in turn
in the outer loop then compare it with all following lines $→(i+1) in
turn in an inner loop, and delete the later line if equal. Scanning
forward in the outer loop and backward in the inner loop ensures that
you don't get line numbers changed before you have finished using them.
But the end-of-loop test for the outer loop must recompute line('$') at
every interation.
Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
124. You begin conversations with, "Who is your internet service provider?"
You are right but if it is only one file and this macro will never be
used as a script to do this automatically etc. it should be fast
enough ;)
Best Regards,
Karol
Oops, I'm sorry I thought you was responding to me...
I must read everything twice before I start to write ;)
Regards,
Karol
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.
:let a={}|g/^/let k=getline('.')|if has_key(a,k)|d|else|let
a[k]=1|endif
:unlet a
This has the advantage that you can do transforms on the key if
you want, changing the "let k=getline('.')" to strip off
leading/trailing whitespace, normalize the case, etc.
Hope this gives you another option,
-tim