-
Notifications
You must be signed in to change notification settings - Fork 36
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
Add support for gg
/G
#23
Comments
j
/k
instead of gj
/gk
j
/k
instead of gj
/gk
Yes |
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}} |
j
/k
instead of gj
/gk
gg
/G
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 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 |
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'}} |
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 |
i have the above in addition to a post hook to set the cursor to the last and first lines for post_hook = function(info)
if info == nil then
return
end
if info.kind == 'gg' then
vim.api.nvim_win_set_cursor(info.winid, { 1, 0 })
elseif info.kind == 'G' then
local line = vim.api.nvim_buf_line_count(info.bufnr)
vim.api.nvim_win_set_cursor(info.winid, { line, 0 })
end
end, |
I added these in my config:
And it turns out that it doesn't work well when there are wrapped lines, because neoscroll uses
gj
andgk
, which is good for other commands like<c-u>
/<c-d>
but bad forgg
andG
.Or is there any way to get the display line number? I didn't find it in help or online.
The text was updated successfully, but these errors were encountered: