TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Sublime Text Ctrl+P Like Fuzzy Matching In Few Lines of Python

69 pointsby cplatalmost 12 years ago

9 comments

crucialfelixalmost 12 years ago
It was actually me that suggested to the TextMate guy to do the fuzzy lookup in this way: matching significant characters in side the search term.<p>AFAIK Sublime, Ctrl-P and friends all followed and improved from TextMate&#x27;s version.<p>It was originally a feature in LaunchBar which was on NextStep and was ported to OS X [1] QuickSilver and Spotlight were also influenced by LaunchBar.<p>[1] <a href="http:&#x2F;&#x2F;www.obdev.at&#x2F;products&#x2F;launchbar&#x2F;legacy.html" rel="nofollow">http:&#x2F;&#x2F;www.obdev.at&#x2F;products&#x2F;launchbar&#x2F;legacy.html</a>
评论 #5888321 未加载
评论 #5892031 未加载
sorbitsalmost 12 years ago
Source for TextMate’s ranker can be found here (GPLv3): <a href="https:&#x2F;&#x2F;github.com&#x2F;textmate&#x2F;textmate&#x2F;blob&#x2F;master&#x2F;Frameworks&#x2F;text&#x2F;src&#x2F;ranker.cc#L46-L192" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;textmate&#x2F;textmate&#x2F;blob&#x2F;master&#x2F;Frameworks&#x2F;...</a><p>And some tests here: <a href="https:&#x2F;&#x2F;github.com&#x2F;textmate&#x2F;textmate&#x2F;blob&#x2F;master&#x2F;Frameworks&#x2F;text&#x2F;tests&#x2F;t_ranker.cc" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;textmate&#x2F;textmate&#x2F;blob&#x2F;master&#x2F;Frameworks&#x2F;...</a>
pjscottalmost 12 years ago
If you want to give more weight to matches of consecutive characters, or do other fancy things, a sequence alignment algorithm could be useful:<p><a href="http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Smith-Waterman_algorithm" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Smith-Waterman_algorithm</a>
评论 #5888260 未加载
评论 #5888181 未加载
spenceraalmost 12 years ago
A slightly more sophisticated implementation: <a href="https:&#x2F;&#x2F;code.google.com&#x2F;p&#x2F;google-diff-match-patch&#x2F;" rel="nofollow">https:&#x2F;&#x2F;code.google.com&#x2F;p&#x2F;google-diff-match-patch&#x2F;</a>
cjh_almost 12 years ago
I implemented something very similar in perl a few weeks back for my user interfaces project; I wrote a desktop search client that would take a query from the user and score results based on how many and how well it matches a series of different interpretations of the query (fuzzy was one of them).<p>I too am really amazed this isn&#x27;t more prevalent as it is so easy to do, after discovering the vim ctrl-p [1] plugin I rarely go a day without using it.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;kien&#x2F;ctrlp.vim" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;kien&#x2F;ctrlp.vim</a>
dangooralmost 12 years ago
For Brackets, I went with something that&#x27;s not a regex because I wanted certain parts of the string to be &quot;special&quot;:<p><a href="http:&#x2F;&#x2F;www.blueskyonmars.com&#x2F;2013&#x2F;03&#x2F;26&#x2F;brackets-quick-open-thats-no-regex&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.blueskyonmars.com&#x2F;2013&#x2F;03&#x2F;26&#x2F;brackets-quick-open-...</a><p>But, I&#x27;ll definitely look up a couple of the links that people have posted here about some other algorithms (Smith-Waterman, for example).
wtingalmost 12 years ago
I had to do something similar for autojump (fuzzy matching search string vs directories list).<p>I started hand rolling my own based on Damerau-Levenshtein, but it turns that Python already has a similar implementation in the difflib:<p><a href="http:&#x2F;&#x2F;docs.python.org&#x2F;2&#x2F;library&#x2F;difflib.html#difflib.get_close_matches" rel="nofollow">http:&#x2F;&#x2F;docs.python.org&#x2F;2&#x2F;library&#x2F;difflib.html#difflib.get_cl...</a>
DrJosiahalmost 12 years ago
I added similar functionality to my editor about 5 years ago after seeing a coworker use Sublime Text. I&#x27;m amazed that all editors don&#x27;t have it already.
评论 #5888027 未加载
评论 #5888410 未加载
gondoalmost 12 years ago
call me old school, but Ctrl + P should do print
评论 #5888226 未加载
评论 #5888460 未加载
评论 #5888311 未加载