Centering after animation
hacker-DOM opened this issue ยท 4 comments
Hi. Firstly thx for the excellent plugin. I would like to center my screen after every animation. Based on the docs, I figured this would do the trick:
require('neoscroll').setup({
post_hook = function(info) vim.cmd [[ normal zz ]] end
})
but it doesn't seem to work. I also tried exe "normal zz"
instead โ๏ธ
i also tried the same thing with no luck ๐ข
this is working for me:
require("neoscroll").setup({
post_hook = function(info)
vim.cmd("normal! zz")
end,
})
I have a feeling that there's a way to use neoscroll.zz
here, although obviously infinite recursion is a concern there xD
EDIT: the behavior still isn't really ideal -- it's exactly what I want for <C-d>
and <C-u>
, but it basically disables zt
, zb
, <C-e>
, and <C-y>
.
Spent a few hours on this -- I'd recommend tweaking the specific numbers / easing function:
local neoscroll = require("neoscroll")
local easing = "sine"
local zz_time_ms = 100
local jump_time_ms = 200
neoscroll.setup({
post_hook = function(info)
if info ~= "center" then
return
end
-- The `defer_fn` is a bit of a hack.
-- We use it so that `neoscroll.init.scroll` will be false when we call `neoscroll.zz`
-- As long as we don't input another neoscroll mapping in the timeout,
-- we should be able to center the cursor.
local defer_time_ms = 10
vim.defer_fn(function()
neoscroll.zz(zz_time_ms, easing)
end, defer_time_ms)
end,
})
local mappings = {}
mappings["<C-u>"] = { "scroll", { "-vim.wo.scroll", "true", jump_time_ms, easing, "'center'" } }
mappings["<C-d>"] = { "scroll", { "vim.wo.scroll", "true", jump_time_ms, easing, "'center'" } }
require("neoscroll.config").set_mappings(mappings)
@zdog234 Thank you for creating this hack, it works with your config, but the scroll speed is too fast for my eyes. I've tried to tweak the number but the following happens:
cute-xgRkt_2.mp4
Basically it'd start to center with zz
before the scrolling is done. It only happens when I scroll at the top of the file, not when the cursor is already centered. I tried tweaking but to no avail. Then I found cinnamon.nvim and with its built-in centered = true
I no longer have the above weird issue. Thanks guys!