Skip to content

Instantly share code, notes, and snippets.

@mattn
Created November 14, 2019 03:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattn/d909c93784aa81d97b82c0896ef38ca8 to your computer and use it in GitHub Desktop.
Save mattn/d909c93784aa81d97b82c0896ef38ca8 to your computer and use it in GitHub Desktop.
function! s:fuzzy(lhs, rhs) abort
return a:lhs =~ join(map(split(a:rhs, '\zs'), "printf('[\\x%02x].*', char2nr(v:val))"), '')
endfunction
let g:asyncomplete_preprocessor =
\ [function('asyncomplete#preprocessor#ezfilter#filter')]
let g:asyncomplete#preprocessor#ezfilter#config = {}
let g:asyncomplete#preprocessor#ezfilter#config['*'] =
\ {ctx, items -> filter(items, 's:fuzzy(v:val.word, ctx.base) != 0')}
@prabirshrestha
Copy link

Try this instead so it does ranking.

if has('python3')
  " osa_filter is slow when running in vim script so only set if python3 is enabled
  let g:asyncomplete_preprocessor =
    \ [function('asyncomplete#preprocessor#ezfilter#filter')]
  let g:asyncomplete#preprocessor#ezfilter#config = {
      \ '*': {ctx, items -> ctx. osa_filter(items, 1)},
      \ }
endif

@machakann
Copy link

I wish vim script gained lshift() function which accelerated osa_filter. The algorithms are different in python and vim script versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment