Skip to content

Commit

Permalink
Fix re-enable &hlsearch ref #82
Browse files Browse the repository at this point in the history
  • Loading branch information
haya14busa committed Jun 3, 2015
1 parent c30b8d9 commit d984b60
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions autoload/incsearch/autocmd.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ nnoremap <silent> <Plug>(_incsearch-nohlsearch) :<C-u>nohlsearch<CR>
xnoremap <silent> <Plug>(_incsearch-nohlsearch) :<C-u>nohlsearch<CR>gv
" :set hlsearch just before :nohlsearch not to blink highlight
noremap <silent> <Plug>(_incsearch-sethlsearch) <Nop>
noremap! <silent> <Plug>(_incsearch-sethlsearch) <Nop>
noremap <silent><expr> <Plug>(_incsearch-sethlsearch) <SID>attach_on_leave()
noremap! <silent><expr> <Plug>(_incsearch-sethlsearch) <SID>attach_on_leave()
nnoremap <silent> <Plug>(_incsearch-sethlsearch) :<C-u>set hlsearch <Bar> nohlsearch<CR>
xnoremap <silent> <Plug>(_incsearch-sethlsearch) :<C-u>set hlsearch <Bar> nohlsearch<CR>gv
Expand Down Expand Up @@ -58,23 +58,32 @@ function! s:noi.on_insert_enter() abort
endfunction

function! s:noi.on_insert_leave() abort
return s:noi.restore_sethlsearch()
endfunction

function! s:noi.restore_sethlsearch() abort
if self.hlsearch
call feedkeys("\<Plug>(_incsearch-sethlsearch)", 'm')
endif
endfunction

function! s:on_insert_enter() abort
call s:noi.on_insert_enter()
augroup incsearch-auto-nohlsearch-on-insert-leave
autocmd!
autocmd InsertLeave * :call <SID>on_insert_leave() | autocmd! incsearch-auto-nohlsearch-on-insert-leave
augroup END
call s:attach_on_leave()
endfunction

function! s:on_insert_leave() abort
call s:noi.on_insert_leave()
endfunction

function! s:attach_on_leave() abort
augroup incsearch-auto-nohlsearch-on-insert-leave
autocmd!
autocmd InsertLeave * :call <SID>on_insert_leave() | autocmd! incsearch-auto-nohlsearch-on-insert-leave
augroup END
return ''
endfunction

let &cpo = s:save_cpo
unlet s:save_cpo
" __END__
Expand Down

0 comments on commit d984b60

Please sign in to comment.