incsearch.vim icon indicating copy to clipboard operation
incsearch.vim copied to clipboard

Strange behavior when working with :terminal

Open tammersaleh opened this issue 5 years ago • 1 comments

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

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
" }}}

tammersaleh avatar Nov 06 '18 19:11 tammersaleh

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.

mars90226 avatar Apr 04 '19 09:04 mars90226