Fix Vim Lag When Coc Highlight or Any Slow Performance on Cursor Hold

May 23, 2021tip slips

Vim/Nvim Lag During Highlighting Text Below Cursor?

This is not an issue during editing small file. But once your file consists 1000+ lines of code like mine on this project. the performance slowness is significantly noticable during scroll up/down using j/k if you are having vim updatetime=100 or even crazier with set updatetime=10.


There are 2 solutions, I personally love the second one. The first solution is just my bullshit to make this post looks longer.

1st Solution: Increase UpdateTime

in .vimrc increase the updatetime to something higher like 3000 or so.

set updatetime=3000 

the problem with this solution is, if you use git gutter, it will analyze any changes of your file longer too which makes a noticable delay anytime you want to see diff added by git. Or even if you use Coc-Highlight, it will highlight any text below cursor just as slow as git gutter analyze your changes.

2nd Solution: Use FixCursorHold.nvim Plugin

Using this method is better since it really is made just to solve this Vim bug.

simply install it:

Plug 'antoinemadec/FixCursorHold.nvim'

use it:

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


Thats all, hope you now procastinating on other thing setting up your workflow.