arrow.nvim icon indicating copy to clipboard operation
arrow.nvim copied to clipboard

Feature: Option to center the cursor (`zz`) if below center

Open keiviv opened this issue 1 year ago • 3 comments

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.

keiviv avatar Jul 05 '24 22:07 keiviv

I'll take a look at this in a little 👀 I do love me some auto centering

tingey21 avatar Jul 10 '24 17:07 tingey21

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

xzbdmw avatar Jul 21 '24 04:07 xzbdmw

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.

keiviv avatar Aug 16 '24 17:08 keiviv