Are there any built-in functions to search sorted list? Such as binary_search, lower_bound, upper_bound, etc.

  • 1
    I don't think so. I have used vimgrep to find something like that but came up empty. – klaus Apr 9 '19 at 1:50
  • Why do you need this? Vim has functions to search lists—do you need performance for a large data set? Push the code to a different level (ie out of vimscript), unless vim can expose the binary search mechanism it uses for tagsfiles. – D. Ben Knoble Apr 9 '19 at 6:14
  • Don't really need it, just curious. – dedowsdi Apr 9 '19 at 6:32

There is nothing built in. But you might check lh-vim-lib.

It has the following functions working on sorted lists:

  • lh#list#equal_range()
  • lh#list#lower_bound()
  • lh#list#upper_bound()
  • 1
    I do indeed provide these functions, but they are quite likely to be less efficient than a naive call to filter(). You'll have to measure both to see what's better suited to the data you're manipulating in your plugins. – Luc Hermitte Apr 9 '19 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.