All Projects → tpope → vim-haystack

tpope / vim-haystack

Licence: other
haystack.vim: fuzzy matching algorithm

Programming Languages

Vim Script
2826 projects

haystack.vim

Haystack provides a fuzzy matching algorithm for use by other Vim plugins. It's based on flx for Emacs but adapted to my own real world experience. The algorithm gives priority to runs of consecutive letters and letters after punctuation marks.

Usage

Haystack defines g:completion_filter with a reference to a function for filtering a list of items based on a user provided query. Plugins can check for this variable and use it if it exists. This level of indirection allows for alternative matching algorithms without the need for plugins to be aware of each one.

So far, out of the box support is included with projectionist.vim, including dependent plugins like rails.vim.

Use with fuzzy finders

Here's a proof of concept for ctrlp.vim.

function! CtrlPMatch(items, str, limit, mmode, ispath, crfile, regex) abort
  let items = copy(a:items)
  if a:ispath
    call filter(items, 'v:val !=# a:crfile')
  endif
  return haystack#filter(items, a:str)
endfunction
let g:ctrlp_match_func = {'match': function('CtrlPMatch')}

Note that the algorithm is slow enough to feel sluggish with larger data sets. You might consider a hybrid approach that uses a different algorithm above a certain number of items.

License

Copyright © Tim Pope. Distributed under the same terms as Vim itself. See :help license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].