From 1d31213a1fa7bf5074446b90c7a8c6c5b93d21f0 Mon Sep 17 00:00:00 2001 From: Axel Detlofsson Date: Thu, 4 Mar 2021 22:09:08 +0100 Subject: [PATCH 1/2] Added sensitivity setting --- README.asciidoc | 6 ++++++ plugin/fuzzysearch.vim | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.asciidoc b/README.asciidoc index 66b8607..723b27e 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -14,6 +14,11 @@ By default, `fuzzysearch` doesn't match over spaces. That means that `"fr"` will If you dislike this behaviour, set `g:fuzzysearch_match_spaces = 1`. The reasoning behind the default behaviour is that it is much easier to narrow down searches, in order to re-use patterns later, for example in a replacement by `:%s///g`. +== Sensitivity +Determine how many wildcard chars between input chars should be a match. +0 = off, input `"fr"` will match `"f.*r"`, 2 will match `"f._._.r"`, 1 `"f._.r"` and so on. +Ex: `g:fuzzysearch_sensitivity = 3` (default is 0) + === Useful mappings Replace in file using last search: `nnoremap r :%s///g` + @@ -25,4 +30,5 @@ I find it very useful to create a fuzzy search quickly, then replace all instanc `g:fuzzysearch_ignorecase = 1` + `g:fuzzysearch_max_history = 30` + `g:fuzzysearch_match_spaces = 0` +`g:fuzzysearch_sensitivity = 0` diff --git a/plugin/fuzzysearch.vim b/plugin/fuzzysearch.vim index fa3b419..872c599 100644 --- a/plugin/fuzzysearch.vim +++ b/plugin/fuzzysearch.vim @@ -4,6 +4,7 @@ let g:fuzzysearch_hlsearch=1 let g:fuzzysearch_ignorecase=1 let g:fuzzysearch_max_history = 30 let g:fuzzysearch_match_spaces = 0 +let g:fuzzysearch_sensitivity = 2 function! s:getSearchHistory() return filter(map(range(1, 20), 'histget("/", v:val-20)'), '!empty(v:val)') @@ -29,11 +30,15 @@ function! s:restoreHistory(histList) let @/=oldSearch endfunction +let s:fuzzySensitivity = '-' +if g:fuzzysearch_sensitivity + let s:fuzzySensitivity = ','.g:fuzzysearch_sensitivity +endif if g:fuzzysearch_match_spaces - let s:fuzzyChars = '.\\{-}' + let s:fuzzyChars = '.\\{'.s:fuzzySensitivity.'}' else - let s:fuzzyChars = '\[^\\ ]\\{-}' + let s:fuzzyChars = '\[^\\ ]\\{'.s:fuzzySensitivity.'}' endif function! s:update(startPos, part) From 11a40c37354a09362d74e61ae7fe6a4de795825e Mon Sep 17 00:00:00 2001 From: Axel Detlofsson Date: Thu, 4 Mar 2021 22:17:15 +0100 Subject: [PATCH 2/2] Set default value to off / 0 --- plugin/fuzzysearch.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/fuzzysearch.vim b/plugin/fuzzysearch.vim index 872c599..f7376cb 100644 --- a/plugin/fuzzysearch.vim +++ b/plugin/fuzzysearch.vim @@ -4,7 +4,7 @@ let g:fuzzysearch_hlsearch=1 let g:fuzzysearch_ignorecase=1 let g:fuzzysearch_max_history = 30 let g:fuzzysearch_match_spaces = 0 -let g:fuzzysearch_sensitivity = 2 +let g:fuzzysearch_sensitivity = 0 function! s:getSearchHistory() return filter(map(range(1, 20), 'histget("/", v:val-20)'), '!empty(v:val)')