3

Can I change / command to execute a fuzzy search instead of a regex based one?

It would be useful to still be able to access the classic / functionality at certain times.

  • If you have a fuzzy find plugin I suppose you could just remap /, n, N, etc. to whatever key(s) bring up search prompt and go forward/back for that. But you won't be able to fundamentally change the native search. – B Layer Dec 8 '17 at 9:38
  • @BLayer what fuzzy find plugins are there? – theonlygusti Dec 8 '17 at 9:40
  • 2
    Here superuser.com/questions/390011/fuzzy-find-within-file-in-vim ... not a lot of choices. – B Layer Dec 8 '17 at 9:46
  • also there are a few options like ignorecase/smartcase that make search a little bit less strict – blues Dec 8 '17 at 10:49
  • You can use VimAwesome to help search for fuzzy plugins. – Peter Rincker Dec 8 '17 at 14:19
2

Try https://github.com/ggvgc/vim-fuzzysearch

Then simply...

nnoremap / :FuzzySearch<CR>
let g:fuzzysearch_prompt = '/'

Then / will take you to a prompt where you enter your pattern and it all looks just like normal Vim. I believe From there n and N will work without modification.

If they aren't already enabled then set incsearch and, possibly, set hlsearch as they enhance that "fuzzy search feeling".

You can optionally tune some other things per your preferences with these settings:

g:fuzzysearch_hlsearch = 1
g:fuzzysearch_ignorecase = 1   
g:fuzzysearch_max_history = 30
g:fuzzysearch_match_spaces = 0

Note that the core functionality of this plugin is pretty simple. It just alters your search term so non-space characters (if g:fuzzysearch_match_spaces is 1 then any characters) are allowed between the characters you enter and submits the updated pattern to native Vim search. But I just tried it and it felt like a decent approach.

To go back to native search nunmap /. You can map the nnoremap and nunmap commands to Normal mode shortcuts to make it really convenient to toggle between the search modes.

| improve this answer | |
  • Even with g:fuzzysearch_match_spaces set to 1 it seems to not match phrases like hi there when searching hh (for example) – theonlygusti Dec 10 '17 at 12:36
  • Hmm. I'll take a look when I get a chance. In the meantime h h should work for that example. – B Layer Dec 10 '17 at 12:57

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.