Skip to content

Commit fa17920

Browse files
committed
support incsearch
1 parent b2ed2fb commit fa17920

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

plugin/incsearch.vim

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
if !get(g:, 'eregex_incsearch_enable', 1)
33
\ || !exists('##CmdlineChanged')
44
\ || !exists('##CmdlineLeave')
5+
\ || !has('timers')
56
finish
67
endif
78

89
augroup eregex_incsearch_augroup
910
autocmd!
10-
autocmd CmdlineChanged * call s:onUpdate()
11+
autocmd CmdlineChanged * call s:delayUpdate()
1112
autocmd CmdlineLeave * call s:onLeave()
1213
augroup END
1314

@@ -19,6 +20,25 @@ if !has('nvim')
1920
cnoremap <expr> <cr> K_eregex_incsearch_abort_cr()
2021
endif
2122

23+
" it's buggy if update immediately on #CmdlineChanged,
24+
" especially for keymap such as
25+
" nnoremap xxx :S/<c-r><c-w>
26+
function! s:delayUpdate()
27+
if get(s:, 'delayUpdateId', -1) == -1
28+
let s:delayUpdateId = timer_start(10, function('s:delayUpdateAction'))
29+
endif
30+
endfunction
31+
function! s:delayUpdateCancel()
32+
if get(s:, 'delayUpdateId', -1) != -1
33+
call timer_stop(s:delayUpdateId)
34+
let s:delayUpdateId = -1
35+
endif
36+
endfunction
37+
function! s:delayUpdateAction(...)
38+
let s:delayUpdateId = -1
39+
call s:onUpdate()
40+
endfunction
41+
2242
function! s:onUpdate()
2343
if getcmdtype() != ':'
2444
\ || !get(b:, 'eregex_incsearch', get(g:, 'eregex_incsearch', &incsearch))
@@ -73,6 +93,8 @@ function! s:onUpdate()
7393
endfunction
7494

7595
function! s:onLeave()
96+
call s:delayUpdateCancel()
97+
7698
if exists('s:hlsearchSaved')
7799
let hlsearchSaved = s:hlsearchSaved
78100
unlet s:hlsearchSaved

0 commit comments

Comments
 (0)