neoscroll.nvim
neoscroll.nvim copied to clipboard
Add support for `gg`/`G`
I added these in my config:
t['gg'] = {'scroll', {'1 - vim.api.nvim_win_get_cursor(0)[1]', 'true', '1', '5', e}}
t['G'] = {'scroll', {'vim.api.nvim_buf_line_count(0) - vim.api.nvim_win_get_cursor(0)[1]', 'true', '1', '5', e}}
And it turns out that it doesn't work well when there are wrapped lines, because neoscroll uses gj
and gk
, which is good for other commands like <c-u>
/<c-d>
but bad for gg
and G
.
Or is there any way to get the display line number? I didn't find it in help or online.
Yes gg
and G
have some complications. The good news is that it is relatively easy to implement inside Neoscroll so the best solution is for me to make wrapper functions like I did for zt
/zz
/zb
.
as a temporary solution you could do something like:
t['gg'] = {'scroll', {'-2*vim.api.nvim_buf_line_count(0)', 'true', '1', '5', e}}
t['G'] = {'scroll', {'2*vim.api.nvim_buf_line_count(0)', 'true', '1', '5', e}}
Similarly, it would be good if pageup and pagedown were captured by neoscroll.
I finally had some time to look at this. I'm not entirely sure what would be the expected behaviour when an easing function is enabled. There are two parts for this animation:
- The window scrolls till the edge of the buffer
- The cursor scrolls till the edge of the buffer
The cursor has to scroll after the window reaches the edge of the buffer because the cursor cannot be at the bottom/top of the window if scrolloff is greater than 0.
Having said that, when an easing function is enabled do we want the easing function to apply to both movements, only on the window scroll movement or only on the cursor movement?
@vext01 You can add map <PageUp> <C-b>
and map <PageDown> <C-f>
to your config. That will make page up and page down do smooth scrolling.
@vext01 You can add
map <PageUp> <C-b>
andmap <PageDown> <C-f>
to your config. That will make page up and page down do smooth scrolling.
Didn't work for me.
@vext01 You can add
map <PageUp> <C-b>
andmap <PageDown> <C-f>
to your config. That will make page up and page down do smooth scrolling.Didn't work for me.
I just duplicated mapping for PageUp and PageDown and it seems to work nicely:
t['<C-b>'] = {'scroll', {'-vim.api.nvim_win_get_height(0)', 'true', '100'}}
t['<PageUp>'] = {'scroll', {'-vim.api.nvim_win_get_height(0)', 'true', '100'}}
t['<C-f>'] = {'scroll', { 'vim.api.nvim_win_get_height(0)', 'true', '100'}}
t['<PageDown>'] = {'scroll', { 'vim.api.nvim_win_get_height(0)', 'true', '100'}}
as a temporary solution you could do something like:
t['gg'] = {'scroll', {'-2*vim.api.nvim_buf_line_count(0)', 'true', '1', '5', e}} t['G'] = {'scroll', {'2*vim.api.nvim_buf_line_count(0)', 'true', '1', '5', e}}
This is great, thanks. The only issue with this for me is that if the file is shorter than the height of the window, then the file will scroll to the last line leaving only the last line of the file visible at the top of the window.
My workaround for this: (only smooth scroll if buffer is longer than window height)
local api = vim.api
vim.keymap.set('n', 'G', [[<Cmd> lua maybe_smooth_scroll()<CR>]], { noremap = true })
function _G.maybe_smooth_scroll()
local win_height = api.nvim_win_get_height(0)
local buf_line_count = api.nvim_buf_line_count(0)
if buf_line_count < win_height then
api.nvim_command('normal! G')
else
require('neoscroll').scroll(1 * buf_line_count, true, 1, 5)
end
end