incsearch.vim
incsearch.vim copied to clipboard
Strange behavior when working with :terminal
I use :term
in Vim 8.0, and every so often when switching to a terminal window, incsearch seems to send (_incsearch-nohlsearch)
to the command line:
![screenshot 2018-11-06 11 28 47](https://user-images.githubusercontent.com/2016/48088564-363c8200-e1b7-11e8-859a-82dc5ec5d654.png)
If I hit enter, then the text is sent to bash, so it's not a visual artifact. The relevant vimrc snippet is:
" Incsearch {{{
set hlsearch
let g:incsearch#auto_nohlsearch = 1
map / <Plug>(incsearch-forward)
map ? <Plug>(incsearch-backward)
map g/ <Plug>(incsearch-stay)
map n <Plug>(incsearch-nohl-n)
map N <Plug>(incsearch-nohl-N)
map * <Plug>(incsearch-nohl-*)
" map # <Plug>(incsearch-nohl-#) " I use tcomment
map g* <Plug>(incsearch-nohl-g*)
map g# <Plug>(incsearch-nohl-g#)
let g:incsearch#separate_highlight = 1
" }}}
I've found a solution. Add the following snippet to the .vimrc
.
augroup incsearch_settings
autocmd!
autocmd BufWinLeave,WinLeave * call s:clear_incsearch_nohlsearch()
augroup END
function! s:clear_incsearch_nohlsearch()
nohlsearch
silent! autocmd! incsearch-auto-nohlsearch
endfunction
Because g:incsearch#auto_nohlsearch = 1
, incsearch.vim will create autocmd after search that will execute :nohlsearch
on CursorMoved
. But in terminal mode, that command will be directly send to your shell without executing. The above snippet will clear the autocmd on BufWinLeave
and WinLeave
which will happen when you leave current window or leave current buffer.