I was really annoyed by this behaviour of neovide animation.
It happened because I remap
ctrl+s
to :w
to save a file, and generally I don't want the cursor to be animated when it goes to the command line. To solve this issue, I use a configuration as follows.
PreviousMode = vim.api.nvim_get_mode().mode
local function animateCursor()
vim.g.neovide_cursor_animation_length = 0.06
vim.g.neovide_cursor_trail_size = 0.7
end
local function stopCursorAnimation()
vim.g.neovide_cursor_animation_length = 0
vim.g.neovide_cursor_trail_size = 0
end
local function callWithDelay(fn, ms)
local timer = vim.loop.new_timer()
timer:start(ms, 0, vim.schedule_wrap(function()
fn()
timer:close()
end))
end
vim.api.nvim_create_autocmd("ModeChanged", {
group = vim.api.nvim_create_augroup("neovide_cursor_handler", { clear = true }),
callback = function()
mode = vim.api.nvim_get_mode().mode
if mode == "c" then
stopCursorAnimation()
else
if PreviousMode == "c" then
stopCursorAnimation()
callWithDelay(animateCursor, 1000)
else
stopCursorAnimation()
end
end
PreviousMode = mode
end,
})
It basically listen to the mode changes in neovim, if it changed to "c"
(represents command line mode) then I stopped the cursor animation. But tricky part is to stop animating cursor after exiting the command line mode, the only implementation I could do is to first stop the animation and then animate back the cursor after a reasonable delay (in my case is 1000 ms).
Hopefully anyone may found this helpful.