Skip to content

Commit

Permalink
feat: use g:cursorhold_updatetime instead of &updatetime
Browse files Browse the repository at this point in the history
Decoupling updatetime from CursorHold allows to have a short cursorhold
updatetime without writing the swap on the disk too often.
See :h updatetime
  • Loading branch information
antoinemadec committed Jul 20, 2020
1 parent ec2d3f4 commit 1097c90
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
Fix Neovim's CursorHold perf bug
Fix CursorHold Performance
=================================

Rationale
---------

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 exists for two reasons:
1. fix neovim **CusorHold** and **CursorHoldI** autocmd events [performance bug][issue]
2. decouple **updatetime** from **CusorHold** and **CursorHoldI** (works for Vim and Neovim)

This plugin fixes this by manually triggering those.
1., fixes slowdowns and untriggered events

This will result in more snapiness for plugins using those events, such as:
2., you can now use small delays for **CursorHold** without writing the swap file 10x/sec (set :h updatetime)

This will result in more snappiness for plugins using those events, such as:
**coc.nvim**, **vim-gutter**, **tagbar**, **vim-devicons**, **vim-polyglot**, etc.

Installation
Expand All @@ -19,6 +22,14 @@ Make sure to have the following plugins in your **vimrc**:
```vim
Plug 'antoinemadec/FixCursorHold.nvim'
```
Configuration
---------

```vim
" in millisecond, used for both CursorHold and CursorHoldI,
" use updatetime instead if not defined
let g:cursorhold_updatetime = 100
```

License
-------
Expand Down
5 changes: 3 additions & 2 deletions plugin/fix_cursorhold_nvim.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
" Maintainer: Antoine Madec <[email protected]>

if exists('g:loaded_fix_cursorhold_nvim') || !has('nvim')
if exists('g:loaded_fix_cursorhold_nvim')
finish
else
let g:loaded_fix_cursorhold_nvim = 'yes'
Expand Down Expand Up @@ -31,5 +31,6 @@ function s:CursorHoldTimer(mode) abort
call timer_stop(g:fix_cursorhold_nvim_timer)
endif
let cb = a:mode == "n" ? 's:CursorHold_Cb' : 's:CursorHoldI_Cb'
let g:fix_cursorhold_nvim_timer = timer_start(&updatetime, function(cb))
let t = get(g:, 'cursorhold_updatetime', &updatetime)
let g:fix_cursorhold_nvim_timer = timer_start(t, function(cb))
endfunction

0 comments on commit 1097c90

Please sign in to comment.