Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Centering after animation #65

Open
hacker-DOM opened this issue Sep 15, 2022 · 4 comments
Open

Centering after animation #65

hacker-DOM opened this issue Sep 15, 2022 · 4 comments

Comments

@hacker-DOM
Copy link

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 ☁️

@jrnxf
Copy link

jrnxf commented Nov 30, 2022

i also tried the same thing with no luck 😢

@znd4
Copy link

znd4 commented Dec 9, 2022

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>.

@znd4
Copy link

znd4 commented Dec 11, 2022

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)

@kohane27
Copy link

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants