Skip to content

Commit

Permalink
feat: add support for CursorHoldI as well
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinemadec committed Jul 13, 2020
1 parent 1a48056 commit ec2d3f4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------
Expand Down
16 changes: 12 additions & 4 deletions plugin/fix_cursorhold_nvim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <nomodeline> 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

0 comments on commit ec2d3f4

Please sign in to comment.