diff --git a/README.md b/README.md index 5eccfed..d84e3ad 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,13 @@ Fix Neovim's CursorHold perf bug Rationale --------- -Neovim's current implementation of **CusorHold** autocmd has a [performance bug][issue] -which causes slowdowns, and sometimes, don't even trigger **CursorHold**. +Neovim's implementations of **CusorHold** and **CursorHoldI** autocmd events have a [performance bug][issue] +which causes slowdowns, and sometimes, don't even trigger those events. -This plugin fixes this by manually triggering **CursorHold**. +This plugin fixes this by manually triggering those. -This will result in more snapiness for plugins using **CursorHold**, such as: -**coc.nvim**, **tagbar**, **vim-devicons**, **vim-polyglot**, etc. +This will result in more snapiness for plugins using those events, such as: +**coc.nvim**, **vim-gutter**, **tagbar**, **vim-devicons**, **vim-polyglot**, etc. Installation --------- diff --git a/plugin/fix_cursorhold_nvim.vim b/plugin/fix_cursorhold_nvim.vim index a419e14..d20bb19 100644 --- a/plugin/fix_cursorhold_nvim.vim +++ b/plugin/fix_cursorhold_nvim.vim @@ -6,11 +6,12 @@ else let g:loaded_fix_cursorhold_nvim = 'yes' endif -set eventignore+=CursorHold +set eventignore+=CursorHold,CursorHoldI augroup fix_cursorhold_nvim autocmd! - autocmd CursorMoved * call s:CursorHoldTimer() + autocmd CursorMoved * call s:CursorHoldTimer("n") + autocmd CursorMovedI * call s:CursorHoldTimer("i") augroup end function s:CursorHold_Cb(timer_id) abort @@ -19,9 +20,16 @@ function s:CursorHold_Cb(timer_id) abort set eventignore+=CursorHold endfunction -function s:CursorHoldTimer() abort +function s:CursorHoldI_Cb(timer_id) abort + set eventignore-=CursorHoldI + doautocmd CursorHoldI + set eventignore+=CursorHoldI +endfunction + +function s:CursorHoldTimer(mode) abort if exists('g:fix_cursorhold_nvim_timer') call timer_stop(g:fix_cursorhold_nvim_timer) endif - let g:fix_cursorhold_nvim_timer = timer_start(&updatetime, function('s:CursorHold_Cb')) + let cb = a:mode == "n" ? 's:CursorHold_Cb' : 's:CursorHoldI_Cb' + let g:fix_cursorhold_nvim_timer = timer_start(&updatetime, function(cb)) endfunction