47571RE: sort & remove duplicate lines?
- Feb 5, 2004I have this in my vimrc file from a previous discussion on this mailling
" Remove duplicate lines (assuming they follow each other).
" Courtesy of Preben 'Peppe' Guldberg, Piet Delport
" Visually select a range of rows and type :Uniq
command! -range=% Uniq <line1>,<line2>g/^\%<<line2>l\(.*\)\n\1$/d
> -----Original Message-----
> From: Benji Fisher [mailto:benji@...]
> Sent: Thursday, February 05, 2004 1:50 PM
> To: vim@...
> Subject: Re: sort & remove duplicate lines?
> On Mon, Feb 02, 2004 at 04:32:58AM +0100, Antoine J. Mechelynck wrote:
> > Let's have a try at it (untested)
> > command Uniq -range=% call RemoveDuplicates()
> > function RemoveDuplicates() range
> > let i = a:firstline + 1
> > let endl = a:lastline
> > while i <= endl
> > if getline(i) == getline(i-1)
> > exe i . "," . i . " delete"
> > let endl = endl - 1
> > else
> > let i = i+1
> > endif
> > endwhile
> > endfunction
> The last time this came up, I think I suggested going
> bottom-up instead of top-down. That is, use
> let i = a:lastline | while i > a:firstline | ... | endwhile
> That way, you never have to change endl. Call it
> "microefficiency" or "elegance," as you see fit. ;)
> --Benji Fisher
- << Previous post in topic Next post in topic >>