Skip to content

Instantly share code, notes, and snippets.

@thinca
Forked from tyru/.vimrc
Created March 20, 2010 19:24
Show Gist options
  • Save thinca/338845 to your computer and use it in GitHub Desktop.
Save thinca/338845 to your computer and use it in GitHub Desktop.
function! s:uniq(list) "{{{
let s:dict = {}
let counter = 1
for i in a:list
if !has_key(s:dict, i)
let s:dict[i] = counter
let counter += 1
endif
endfor
function! s:cmp(a, b)
return a:a == a:b ? 0 : a:a > a:b ? 1 : -1
endfunction
function! s:c(a, b)
let [a, b] = [a:a, a:b]
return eval(s:expr)
endfunction
try
let s:expr = 's:cmp(s:dict[a], s:dict[b])'
return sort(keys(s:dict), 's:c')
finally
delfunc s:cmp
delfunc s:c
unlet s:expr
unlet s:dict
endtry
endfunction "}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment