[vim/vim] Some way to prevent cursor flickering (Issue #11918)

111 views
Skip to first unread message

monkoose

unread,
Jan 30, 2023, 3:40:45 PM1/30/23
to vim/vim, Subscribed

TL;DR some plugins which do some computation + redrawing causing cursor to flicker

screencast example

I'm using a combination of pretty popular plugins: ALE + CoC which have some autocmds on CursorHold, InsertLeave etc, which process some lsp/linting behind the scenes. They are working fine, but also are a cause of the cursor flickering (starting visible in some big files 1000+ lines) as shown in the screencast above.

This behavior can be replicated with something like this

vim9script

def HeavyComputation(_): number
  var sum = 0
  redraw
  for _ in range(200000)  # adjust loop size if flickering still not visible on your machine or you can set it very big to completely hide the cursor for the time of computation
    sum += 2
  endfor
  return sum
enddef

augroup HelloOpana
  autocmd!
  autocmd CursorHold * timer_start(1, HeavyComputation)
  autocmd CursorHold * timer_start(20, HeavyComputation)
  autocmd CursorHold * timer_start(40, HeavyComputation)
augroup END

defcompile

My assumption this is happening when redraw follows some heavy computation. If we remove redraw from this code then flickering is gone. Is there a reason for such behavior that cursor is hidden until this computation happens? Can it be prevented somehow?


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11918@github.com>

Bram Moolenaar

unread,
Jan 31, 2023, 9:25:32 AM1/31/23
to vim/vim, Subscribed


> TL;DR some plugins which do some computation + redrawing causing
> cursor to flicker
>
> [screencast example](https://user-images.githubusercontent.com/6261276/215587343-9c2ccc2c-0424-43c9-b49f-f2798ada1acd.mp4)

>
> I'm using a combination of pretty popular plugins:
> [ALE](https://github.com/dense-analysis/ale) +
> [CoC](https://github.com/neoclide/coc.nvim) which have some autocmds

> on CursorHold, InsertLeave etc, which process some lsp/linting behind
> the scenes. They are working fine, but also are a cause of the cursor
> flickering (starting visible in some big files 1000+ lines) as shown
> in the screencast above.
>
> This behavior can be replicated with something like this

[...]

Vim will hide the cursor while updating the screen. This avoids the
cursor flashing around while drawing text.

The cursor is enabled again before Vim starts waiting for the user to
type something. In your example the HeavyComputation() is causing some
time to pass before this, hence the noticeable flicker.

There is a trick you could try: After the :redraw command, use a :sleep
command with a very short time. Thus:

:redraw
:sleep 1m

For me this removes the flicker.

--
hundred-and-one symptoms of being an internet addict:
75. You start wondering whether you could actually upgrade your brain
with a Pentium Pro microprocessor 80. The upgrade works just fine.

/// Bram Moolenaar -- ***@***.*** -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11918/1410449186@github.com>

monkoose

unread,
Jul 25, 2023, 3:04:21 PM7/25/23
to vim/vim, Subscribed

Closed #11918 as completed.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/11918/issue_event/9915400785@github.com>

Reply all
Reply to author
Forward
0 new messages