support incsearch - #29
Conversation
huyz
commented
Nov 9, 2022
This is awesome. Thanks @ZSaberLv0 ! |
huyz
commented
Nov 9, 2022
And thanks @othree as well of course :) |
othree
commented
Nov 9, 2022
@ZSaberLv0 is this ready for review? I see you kept pushing new commits when you created the PR. So I am waiting. |
ZSaberLv0
commented
Nov 9, 2022
it's ready for review, I have tested for these days, no further issue found for my case |
Question: nnoremap//\cnnoremap??\cIn the case of eregex, I now do the same with nnoremap<expr>/":<C-U>".v:count1."M/\\c"nnoremap<expr>?":<C-U>".v:count1."M?\\c"The problem is that I guess another solution for me would be if eregex could support separate Not a big deal, either way. |
maybe we can add user defined pattern filter around here: incsearch.vim#L53 let Fn_filter =get(b:, 'Fn_eregex_incsearch_filter', get(g:, 'Fn_eregex_incsearch_filter', ''))
if!empty(Fn_filter) &&Fn_filter(cmd['pattern'])
ifexists('s:patternSaved')
let@/=s:patternSavedendififexists('s:stateSaved')
callwinrestview(s:stateSaved)
endifredraw!returnendif |
huyz
commented
Nov 9, 2022
@ZSaberLv0 A user-defined filter would be great for me. |
huyz
commented
Nov 10, 2022
Great, it works fine for me now if I do This is my " We want `:S` substitutions to be case-sensitive.letg:eregex_force_case=1" Disable the default mappings because we have to do the mapping ourselvesletg:eregex_default_enable=0letg:eregex_forward_delim='/'letg:eregex_backward_delim='?'" Avoid total-file highlight because of the additional `\c`letg:Fn_eregex_incsearch_filter= {x-> x=='\c'}
" Code from eregex.vimlets:enable=0function!EregexToggle(...)
letsilent=0ifexists('a:1') &&a:1letsilent=1endififs:enable==0exec'nnoremap <expr> '.g:eregex_forward_delim.' ":<C-U>".v:count1."M/\\c"'exec'nnoremap <expr> '.g:eregex_backward_delim.' ":<C-U>".v:count1."M?\\c"'ifsilent!=1echo"eregex.vim key mapping enabled"endifelseexec'nunmap '.g:eregex_forward_delimexec'nunmap '.g:eregex_backward_delimifsilent!=1echo"eregex.vim key mapping disabled"endifendiflets:enable=1-s:enableendfuncallMapKey('<M-t>/', '<Cmd>call EregexToggle()<CR>')
" Start out enabledcallEregexToggle(v:true) |
huyz
commented
Nov 10, 2022
There might be another issue. I have: setignorecasesmartcaseletg:eregex_force_case=1So if I type |
huyz
commented
Nov 10, 2022
Thanks a lot for the quick turnaround! Looks good so far. |
huyz
commented
Nov 27, 2022
I think it's a good time to review and merge :) |
ZSaberLv0
commented
Nov 29, 2022
add support for custom cmdparser, a typical config for function!Easygrep_incsearch(cmdline)
let cmd =substitute(a:cmdline, ' .*', '', '')
if cmd =='Grep'return {
\ 'method' : cmd,
\ 'delim' : '/',
\ 'modifiers' : '',
\ 'pattern' : substitute(a:cmdline, '^ *[^ ]\+ \+', '', ''),
\ }
elseif cmd =='Replace'let slashToken =nr2char(127)
let cmdline =substitute(a:cmdline, '^ *[^ ]\+ \+', '', '')
let cmdline =substitute(cmdline, '\\/', slashToken, 'g')
letitems=split(cmdline, '/')
ifempty(items)
return {}
endifreturn {
\ 'method' : cmd,
\ 'delim' : '/',
\ 'modifiers' : '',
\ 'pattern' : substitute(items[0], slashToken, '\\/', 'g'),
\ }
elsereturn {}
endifendfunctionletg:eregex_incsearch_custom_cmdparser= {
\ 'easygrep' : function('Easygrep_incsearch'),
\ } |
add incsearch support, for
:M/:S/:G/:V/command, and:M?backward search serieslimitations:
exists('##CmdlineChanged') && exists('##CmdlineLeave'), to simulate incsearchcmapa to zto simulate incsearch, but that would cause much more troublehas('timers'), to prevent some buggy behavior when used in keymaps, such asnnoremap xxx :S/<c-r><c-w>vim, added acmap <cr>due to lack ofneovim'sv:event['abort']ofCmdlineLeave, which may break user's custom keymap:M/canceled by<esc>or<c-c>