Feature: Option to center the cursor (`zz`) if below center
Amazing plugin, and an option to auto-zz if below center would be useful. I've tried to add it in custom_actions, but it needs to be after the return, and also work on previous • next. The code is quite simple to implement:
if vim.fn.line('.') > vim.fn.winheight(0) / 2 then
vim.cmd('normal! zz')
end
or similar. The option name could be smart_center.
I'll take a look at this in a little 👀 I do love me some auto centering
Can you try
open = function(target_file_name, current_file_name)
vim.api.nvim_create_autocmd("BufEnter", {
once = true,
callback = function()
vim.api.nvim_create_autocmd("CursorMoved", {
once = true,
callback = function()
if vim.fn.line(".") > vim.fn.winheight(0) / 2 then
vim.cmd("normal! zz")
end
end,
})
end,
})
vim.cmd("e " .. target_file_name)
end, -- target_file_name = file selected to be open, current_file_name = filename from where this was called
Can't test due to health issues, but it does look like autocmd would work. But I do think it'd be cooler to implement at the plugin level — as it does not add much code or overhead, and is a practically useful option — leaving a cursor at the end is quite common, and an option to center it vertically is nice.