diff --git a/.config/vim/vimrc.d/80-autocommands.vim b/.config/vim/vimrc.d/80-autocommands.vim index fd18c5c..15cc354 100644 --- a/.config/vim/vimrc.d/80-autocommands.vim +++ b/.config/vim/vimrc.d/80-autocommands.vim @@ -110,6 +110,10 @@ function! s:highlight_selection() " Kill the possibly already running timer if exists('w:selection_timer_id') call timer_stop(w:selection_timer_id) + " Make sure that the old selection is deleted soon-ish + if exists("w:visual_match_ids") && !exists("w:selection_clear_timer_id") + let w:selection_clear_timer_id = timer_start(150, 's:clear_visual_timer') + endif endif " Delay the highlight by 100ms so that not every selection is highlighted @@ -121,6 +125,11 @@ endfunction function! s:_highlight_selection(timer) unlet w:selection_timer_id + if exists("w:selection_clear_timer_id") + call timer_stop(w:selection_clear_timer_id) + unlet w:selection_clear_timer_id + endif + let l:old_reg = getreg('"') let l:old_regtype = getregtype('"') " NOTE: The yank needs to be silent to mute the 'n lines yanked' @@ -189,6 +198,11 @@ function! s:clear_highlights(what = s:CLEAR_HIGHS_ALL) endif endfunction +function! s:clear_visual_timer(timer) + unlet w:selection_clear_timer_id + call s:clear_highlights(s:CLEAR_HIGHS_VISUAL) +endfunction + augroup highlight_current au! " TODO: `viw` when on the last character of the word does not trigger