From 1097c900a6f2a41a59d0bc700dc5bcda9ba43460 Mon Sep 17 00:00:00 2001 From: antoinemadec Date: Mon, 20 Jul 2020 12:46:14 -0700 Subject: [PATCH] feat: use g:cursorhold_updatetime instead of &updatetime Decoupling updatetime from CursorHold allows to have a short cursorhold updatetime without writing the swap on the disk too often. See :h updatetime --- README.md | 21 ++++++++++++++++----- plugin/fix_cursorhold_nvim.vim | 5 +++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d84e3ad..70f71e4 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 ------- diff --git a/plugin/fix_cursorhold_nvim.vim b/plugin/fix_cursorhold_nvim.vim index d20bb19..17feb1f 100644 --- a/plugin/fix_cursorhold_nvim.vim +++ b/plugin/fix_cursorhold_nvim.vim @@ -1,6 +1,6 @@ " Maintainer: Antoine Madec -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' @@ -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