Giter Club home page Giter Club logo

neoscroll.nvim's Introduction

Neoscroll: a smooth scrolling neovim plugin written in lua

Demo

demo.mp4

Features

  • Smooth scrolling for window movement commands (mappings optional): <C-u>, <C-d>, <C-b>, <C-f>, <C-y>, <C-e>, zt, zz, zb.
  • Takes into account folds.
  • A single scrolling function that accepts either the number of lines or the percentage of the window to scroll.
  • Scroll any window.
  • Cursor is hidden while scrolling (optional) for a more pleasing scrolling experience.
  • Customizable scrolling behaviour.
  • You can use predefined easing functions for the scrolling animation.
  • Performance mode that turns off syntax highlighting while scrolling for slower machines or files with heavy regex syntax highlighting.
  • Cancel scroll by scrolling in the opposite direction.
  • Simulated "stop on key release" when holding down a key to scroll.

Installation

You will need neovim 0.5 for this plugin to work. Install it using your favorite plugin manager:

  • With Packer: use 'karb94/neoscroll.nvim'

  • With vim-plug: Plug 'karb94/neoscroll.nvim'

  • With lazy.nvim, create the file ~/.config/nvim/lua/plugins/neoscroll.lua:

    return {
      "karb94/neoscroll.nvim",
      config = function ()
        require('neoscroll').setup({})
      end
    }

Options

Read :help neoscroll-options for a detailed description of all the options.

setup() with all the options and their default values:

require('neoscroll').setup({
  mappings = {                 -- Keys to be mapped to their corresponding default scrolling animation
    '<C-u>', '<C-d>',
    '<C-b>', '<C-f>',
    '<C-y>', '<C-e>',
    'zt', 'zz', 'zb',
  },
  hide_cursor = true,          -- Hide cursor while scrolling
  stop_eof = true,             -- Stop at <EOF> when scrolling downwards
  respect_scrolloff = false,   -- Stop scrolling when the cursor reaches the scrolloff margin of the file
  cursor_scrolls_alone = true, -- The cursor will keep on scrolling even if the window cannot scroll further
  easing = 'linear',           -- Default easing function
  pre_hook = nil,              -- Function to run before the scrolling animation starts
  post_hook = nil,             -- Function to run after the scrolling animation ends
  performance_mode = false,    -- Disable "Performance Mode" on all buffers.
})

You can map a smaller set of default mappings:

require('neoscroll').setup({ mappings = {'<C-u>', '<C-d>', '<C-b>', '<C-f>'} })

Or you can disable all default mappings by passing an empty list:

require('neoscroll').setup({ mappings = {} })

The section below explains how to create your own custom mappings.

Custom mappings

You can create your own scrolling mappings using the following lua functions:

  • scroll(lines, opts)
  • ctrl_u
  • ctrl_d
  • ctrl_b
  • ctrl_f
  • zt(half_win_duration, opts)
  • zz(half_win_duration, opts)
  • zb(half_win_duration, opts)

Read :help neoscroll-functions for more details.

You can use the following syntactic sugar in your init.lua to define lua function mappings in normal, visual and select modes:

neoscroll = require('neoscroll')
local keymap = {
  ["<C-u>"] = function() neoscroll.ctrl_u({ duration = 250 }) end;
  ["<C-d>"] = function() neoscroll.ctrl_d({ duration = 250 }) end;
  ["<C-b>"] = function() neoscroll.ctrl_b({ duration = 450 }) end;
  ["<C-f>"] = function() neoscroll.ctrl_f({ duration = 450 }) end;
  ["<C-y>"] = function() neoscroll.scroll(-0.1, { move_cursor=false; duration = 100 }) end;
  ["<C-e>"] = function() neoscroll.scroll(0.1, { move_cursor=false; duration = 100 }) end;
  ["zt"]    = function() neoscroll.zt({ half_win_duration = 250 }) end;
  ["zz"]    = function() neoscroll.zz({ half_win_duration = 250 }) end;
  ["zb"]    = function() neoscroll.zb({ half_win_duration = 250 }) end;
}
local modes = { 'n', 'v', 'x' }
for key, func in pairs(keymap) do
  vim.keymap.set(modes, key, func)
end

Easing functions

By default the scrolling animation has a constant speed (linear), i.e. the time between each line scroll is constant. If you want to smooth the start and end of the scrolling animation you can pass the name of one of the easing functions that Neoscroll provides to the scroll() function. You can use any of the following easing functions: linear, quadratic, cubic, quartic, quintic, circular, sine. Neoscroll will then adjust the time between each line scroll using the selected easing function. This dynamic time adjustment can make animations more pleasing to the eye.

To learn more about easing functions here are some useful links:

Examples

Using the same syntactic sugar introduced in Custom mappings we can write the following config:

neoscroll = require('neoscroll')
neoscroll.setup({
  -- Default easing function used in any animation where
  -- the `easing` argument has not been explicitly supplied
  easing = "quadratic"
})
local keymap = {
  -- Use the "sine" easing function
  ["<C-u>"] = function() neoscroll.ctrl_u({ duration = 250; easing = 'sine' }) end;
  ["<C-d>"] = function() neoscroll.ctrl_d({ duration = 250; easing = 'sine' }) end;
  -- Use the "circular" easing function
  ["<C-b>"] = function() neoscroll.ctrl_b({ duration = 450; easing = 'circular' }) end;
  ["<C-f>"] = function() neoscroll.ctrl_f({ duration = 450; easing = 'circular' }) end;
  -- When no value is passed the `easing` option supplied in `setup()` is used
  ["<C-y>"] = function() neoscroll.scroll(-0.1, { move_cursor=false; duration = 100 }) end;
  ["<C-e>"] = function() neoscroll.scroll(0.1, { move_cursor=false; duration = 100 }) end;
}
local modes = { 'n', 'v', 'x' }
for key, func in pairs(keymap) do
    vim.keymap.set(modes, key, func)
end

pre_hook and post_hook functions

Set pre_hook and post_hook functions to run custom code before and/or after the scrolling animation. The function will be called with the info parameter which can be optionally passed to scroll() (or any of the provided wrappers). This can be used to conditionally run different hooks for different types of scrolling animations.

For example, if you want to hide the cursorline only for <C-d>/<C-u> scrolling animations you can do something like this:

require('neoscroll').setup({
  pre_hook = function(info) if info == "cursorline" then vim.wo.cursorline = false end end,
  post_hook = function(info) if info == "cursorline" then vim.wo.cursorline = true end end
})
local keymap = {
  ["<C-u>"] = function() neoscroll.ctrl_u({ duration = 250; info = 'cursorline' }) end;
  ["<C-d>"] = function() neoscroll.ctrl_d({ duration = 250; info = 'cursorline' }) end;
}
local modes = { 'n', 'v', 'x' }
for key, func in pairs(keymap) do
  vim.keymap.set(modes, key, func)
end

Keep in mind that the info variable is not restricted to a string. It can also be a table with multiple key-pair values.

Known issues

  • <C-u>, <C-d>, <C-b>, <C-f> mess up macros (issue).

Acknowledgements

This plugin was inspired by vim-smoothie and neo-smooth-scroll.nvim. Big thank you to their authors!

neoscroll.nvim's People

Contributors

3719e04 avatar bbenzikry avatar chomosuke avatar chyeh avatar davidrambo avatar folke avatar gshpychka avatar haooodev avatar karb94 avatar numtostr avatar pandar00 avatar scrouthtv avatar stevanmilic avatar tarundacoder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

neoscroll.nvim's Issues

Scrolling not smooth when using nvim-treesitter-context

I am not sure whether to post this here or in the nvim-treesitter-context issues.

When scrolling with the above mentioned plugin enabled and some context is shown in the first lines of the window, the scrolling gets somewhat whacky. I guess this is due to treesitter-context updating the info on each movement (each step of the scrolling), which is time consuming when added up. Does anyone know a way of telling nvim-treesitter-context to analyze the position in the buffer just after the scrolling is finished?

Here is a gif of the problem. One can see smooth scrolling in the first buffer, where no context is shown. In the second buffer, the plugin shows some context and scrolling starts to stutter.
GIF 9-12-2022 2-52-28 PM

This is merely a small aesthetic problem, but I thought I'd ask here as neoscroll is all about smoothness :)

Expose API

expose the lua functions as an api so one can trigger a scroll however they desire

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.

scrolling jumps up and down

since the last commit my scrolling via ctrl+d and ctrl+u jumps around. i recorded my screen to show it. thanks for this great plugin!

scrollup-2022-06-15_12.50.22.mp4

move content of .vim file to explicit lua initialisation by user

I like the plugin very much. Thanks alot for creating!

Reasons to do:

  1. A pure lua profile would decrease startup time.
  2. The lua startup profiler would be more correct or simpler to get correct with this change. Otherwise one gets more wrong results.
  3. Try to be consistent as to use functionality of lua, if possible.
  4. Having a function to initialize makes separating things for user-specific settings while getting updates much easier (user may implement a different function to customize plugin).

Another related reason (bad practice/historical reasons): nvim-treesitter/module-template#1

Relevant content for change:
https://github.com/nanotee/nvim-lua-guide#using-meta-accessors-1

Is the problem potentially that there is standard way to define description + maintainer for tools to read?

" Smooth scrolling plugin
" Maintainer: Carles Rafols i Belles

Sidenode: Luajit caches stuff (for speed reasons), so when no vimscript is involved or a function changes settings, they will remain.

When scroll to the bottom or to the top, cursor is not being moved

Hello! First, thank you for this plugin. It is REALLY awesome and I love to scroll on my buffers with it. But, I noted a problem when I try to scroll to the end or top of a buffer. The scroll occours normally, but the cursor is not being move to the last line or the first line of the buffer when it hit the top or bottom of a buffer.

This video show what I'm talking about, please keep track of the cursor position when I try to scroll using and (the first part is not using the plugin and the second is using it):

gravacao-de-tela-2021-03-31-as-142217_WLe9DRZX.mov

Pre-scrolling and post-scrolling hooks

Trigger a custom User autocommands before and after scrolling. Maybe separate events depending on the type of scroll or alternatively (and probably better) exposing different variables from the plugin that users can use to trigger actions depending on the scrolling state.

Please comment if you are interested in seeing this implemented an how you would use it so that I have a clearer idea of what needs to be done.

README example missing comma to work

Hello @karb94,

Congrats for this great plugin!
Just a quick correction, in Options section of the README, a comma is missing which makes the example unusable as is.

Here is the example with the typo fixed:

require('neoscroll').setup({
    -- All these keys will be mapped. Pass an empty table ({}) for no mappings
    mappings = {'<C-u>', '<C-d>', '<C-b>', '<C-f>',
                '<C-y>', '<C-e>', 'zt', 'zz', 'zb'},
    hide_cursor = true,          -- Hide cursor while scrolling
    stop_eof = true,             -- Stop at <EOF> when scrolling downwards
    respect_scrolloff = false,   -- Stop scrolling when the cursor reaches the scrolloff margin of the file
    cursor_scrolls_alone = true,  -- The cursor will keep on scrolling even if the window cannot scroll further
    easing = false,              -- easing_function will be used in all scrolling animations with some defaults
    easing_function = function(x) return math.pow(x, 2) end -- default easing function
})

Cheers!

Reverse key press stop scrolling

Thanks for the great plugin ❤️

I am just wondering if it is possible to stop scrolling by pressing the reverse scrolling key, for example, I am pressing <C-d> for scrolling down, and suddenly I want to stop scrolling by pressing <C-u>.

I used to use comfortable-motion.vim, and it does have this little piece I want.

Cheers,
Jake

Handle wrapped lines gracefully

Scrolling over wrapped lines is inconsistent. Need to figure out a way to check what lines are wrapped. Not sure if it's even possible.

Move cursor instantly for <C-u> and similar

At the moment, the cursor animates with screen movement and mess up macroses. I also personally find this behavior less comfortable.
It would be better if the cursor moves instantly and the screen moves smoothly. There is awesome scroll.vim in Vimscript that do the same thing.
It would be awesome to have an option for this or even make this as a default behavior.

Change time_step "Globally"

I couldn't find it in the documentation, but is there a way to change the time_step for all the commands, for me the default is quite slow. If not, something maybe like this could be nice:

require('neoscroll').setup({
    mappings = {'<C-u>', '<C-d>', '<C-b>',
        '<C-f>', '<C-y>', '<C-e>', 'zt', 'zz', 'zb'},
    hide_cursor = true,
    stop_eof = true,
    respect_scrolloff = false,
    cursor_scrolls_alone = true,
    time_step = 5  -- This option?
})

neoscroll.G is not moving cursor to the last line

Hitting G only scrolling the file to the end but the cursor still remains at the same position.

2022-05-28.10.40.56.mov

Perhaps it should be

neoscroll.scroll(lines+win_lines_below_cursor, true, corrected_time, easing, { G = true })

in line 395 ?

Ctrl-D does not work when scrolloff is a big value

Ctrl-D does not work right if scrolloff is big, for example scrolloff=999. Steps to reproduce are:

  1. Execute set scrolloff=999.
  2. Press Ctrl-D to scroll down.
  3. You should see that smooth scrolling is not applied.

[Feature request] Implement scrolling for an arbitrary window

Basically title. Currently, as far as I can tell, only supported for current window.

Why: to scroll popup/preview/qf/diagnostics windows without having to move the cursor there. Especially annoying if the hover() documentation does not fit in the popup.

I initially tried to do something like vim.fn.win_execute(winid, "lua require'nescroll'.scroll(...)"), but that only scrolls the window for one line and then keeps scrolling the current one. From the looks of it, implementing this would require refactoring some globals into per-winid tables and calling vim.fn.* (such as winline()) inside win_execute context - which is a handful, but possible.

I'm just moving from Vim to Neovim and learning Lua, but I would be happy to take a crack at it in a PR. However, if the feature is not needed or impossible for some reason I can't see, please let me know.

`nzz` and `Nzz` not working

First of all, thanks for the plugin. It's really great and works flawlessly 99% of the time.

I have a mapping that makes my n maps to nzz, so the search term is always kept in the center of the screen.

When using neoscroll, for some reason, nzz puts me on the line before the actual search term, so I'm "stuck" since the 'next' is always the ocurrence I just found.

Not sure if there's an easy way to fix this, but it would be great to keep my nzz mappings and still use neoscroll for zz.

Steps to reproduce:

  • nnoremap n nzz
  • Setup neoscroll:
neoscroll.setup({
   		-- All these keys will be mapped to their corresponding default scrolling animation
   		mappings = {
   			"<C-u>",
   			"<C-d>",
   			"<C-b>",
   			"<C-f>",
   			"<C-y>",
   			"<C-e>",
   			"zt",
   			"zz",
   			"zb",
   		},
   		hide_cursor = true, -- Hide cursor while scrolling
   		stop_eof = true, -- Stop at <EOF> when scrolling downwards
   		use_local_scrolloff = false, -- Use the local scope of scrolloff instead of the global scope
   		respect_scrolloff = false, -- Stop scrolling when the cursor reaches the scrolloff margin of the file
   		cursor_scrolls_alone = true, -- The cursor will keep on scrolling even if the window cannot scroll further
   	})
  • Open a large file an search for anything. Press n to go to the next match and see that the cursor actually lands on the line before it

This issue doesn't happen in smaller files. If the content fits in the window, it works as expected

Normal command argument error following scrolloff changes

Hi 👋🏾 ,

Thanks for your work on this plugin I've been using if for a while now and it's been really smooth sailing. Recently some changes relating to scrolloff have been added which seem to have triggered a new error in my setup which then causes the cursor to remain hidden.
When I scroll using <c-d> , <c-u> I see

E5108: Error executing lua .../pack/packer/start/neoscroll.nvim/lua/neoscroll/init.lua:198: Vim(normal):E471: Argument required: normal!

I have some scrolloff options in my init.lua specifically

vim.opt.scrolloff = 9
vim.opt.sidescrolloff = 10
vim.opt.sidescroll = 1

Removing these doesn't seem to help though and the error occurs anyway.
I have this plugin configured using

        require("neoscroll").setup {
          mappings = { "<C-u>", "<C-d>", "<C-b>", "<C-f>", "<C-y>", "zt", "zz", "zb" },
          stop_eof = false,
        }

I noticed this after the most recent change in master so rolled back to the last working commit which was the one before the scrolloff change. I also briefly noticed this a few days ago when I think a similar change was introduced then reverted.

Let me know if I can provide any more information.

Move cursor with page when scrolling

Hello,

Thanks for this great plugin, it's working pretty great even on my 4K monitor (with Kitty)!

I have a question about the configuration. Currently I have this setup in my init.lua based on the latest commits:

neoscroll.setup({
  mappings = {'<C-u>', '<C-d>', '<C-b>',
    '<C-f>', '<C-y>', '<C-e>', 'zz'},
  hide_cursor = true,          
  stop_eof = false,             
  respect_scrolloff = true,   
  cursor_scrolls_alone = false,  
})

and remapped some keys like this:

utils.nnoremap('<C-y>', ":lua require('neoscroll').scroll(-3, true, 12)<cr>")
utils.nnoremap('<C-e>', ":lua require('neoscroll').scroll(3, true, 12)<cr>")

I really liked before that with vim, when you scroll one line up, the cursor stayed on the same line number.
If it was on line 42 and you scroll up 3 lines it will still be on line 42. (or was it because of vim-smoothie ? 🤔)

Do you think it's possible to get the same behaviour with neoscroll ? I tried cursor_scrolls_alone with true|false but didn't see a difference.

Disable smooth scroll in small windows...

Is there any option to disable smooth scroll in small-height windows, I think it is better to scroll these few lines immediately without experiencing this non-smooth scroll.

simplescreenrecorder-2022-02-23_00.27.36-reduced.mp4

E5108 attempt to index a nil value

Following up this comment.
I just installed neoscroll, using Vim Plug, and all the bindings give this message.

E5108: Error executing lua ...onfig/nvim/plugged/neoscroll.nvim/lua/neoscroll/init.lua:306: attempt to index a nil value

Line 306 of init.ula is:

    if data.win_lines_above_cursor <= vim[so_scope].scrolloff then

I include the whole of that file at the end of this issue.

This is my whole init.vim, no other plugins are loaded.

if empty(glob('~/.config/nvim/autoload/plug.vim'))
  silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  autocmd VimEnter * PlugInstall | source $MYVIMRC
endif

call plug#begin()
  Plug 'karb94/neoscroll.nvim'
call plug#end()
lua require('neoscroll').setup()

And this is what vim says when I ask it what version it has:

:version                                                                                                                                                                       
NVIM v0.5.0-dev+1357-g192f89ea1
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/cc -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissin
g-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNV
IM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/build/nvim/parts/nvim/build/build/config -I/build/nvim/parts/nvim/build/src -I/build/nvim/parts/nvim/build/.deps/usr/include -I/usr/include -
I/build/nvim/parts/nvim/build/build/src/nvim/auto -I/build/nvim/parts/nvim/build/build/include
Compiled by root@lgw01-amd64-021

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

Cursor is always hidden

Cursor is hidden even when not scrolling and with neoscroll_hide_cursor_line = 0
I even tried defining neoscroll_hide_cursor_line before loading plugins:
init.lua -

local api = vim.api

api.nvim_command("packadd packer.nvim")
vim.o.termguicolors = true
vim.g["conjure#mapping#doc_word"] = "K"
vim.g.neoscroll_hide_cursor_line = 0
local packer = require("packer")
local packages = require("packages")

packer.startup(function()
    for _, value in pairs(packages) do
        packer.use(value)
    end
end)

`zt` goes all the way up and `zb` goes all the way to down

First of all thanks for this lovely plugin ❤️ . This plugin is awesome.

Back to the issue, So, When you press zt, the cursor goes all the way to the top, and zb goes all the way down but zz works great. This is not the expected behavior of the vanilla commands.

neoscroll-2.mp4

Error on Neovim Startup

Neovim throws an error on startup with neoscroll installed.

Info about my system:

  • Neovim version: 0.5.0-dev+1221-g9b2d4ff62
  • Package manager: Junegunn's vim plug
  • Startup: init.vim
  • Running Debian via WSL if that makes a difference?

Here is the exact error message:

Error detected while processing /home/shreeram/dotfiles/nvim/.config/nvim/init.vim:
line  118:
E5108: Error executing lua [string ":lua"]:1: module 'neoscroll' not found:
        no field package.preload['neoscroll']
        no file './neoscroll.lua'
        no file '/home/runner/work/neovim/neovim/.deps/usr/share/luajit-2.1.0-beta3/neoscroll.lua'
        no file '/usr/local/share/lua/5.1/neoscroll.lua'
        no file '/usr/local/share/lua/5.1/neoscroll/init.lua'
        no file '/home/runner/work/neovim/neovim/.deps/usr/share/lua/5.1/neoscroll.lua'
        no file '/home/runner/work/neovim/neovim/.deps/usr/share/lua/5.1/neoscroll/init.lua'
        no file './neoscroll.so'
        no file '/usr/local/lib/lua/5.1/neoscroll.so'
        no file '/home/runner/work/neovim/neovim/.deps/usr/lib/lua/5.1/neoscroll.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'

With reference to the error here is line 118 of my init.vim

115 
116 Plug 'karb94/neoscroll.nvim'
117
118 lua require('neoscroll').setup()
119

One odd thing I noticed is that after startup if I go and manually source my init.vim, full functionality of neoscroll returns and there is no error, so this seems to only be an issue with startup.

If there's any other info you need please let me know, neoscroll has been by far the best smooth scroll plugin I've used so I'd love to help in any way I can =)

Error ... attempt to index a nil value

Detail

Recently I've encountered an unexpected error when I press down CTRL+D to scroll down. Same error happened to +U.
image

Thought this commit caused issue.
1de7d03

I also tried with some former commits, they are all good to me.

How to reproduce

Open any file and press down CTRL+D. The page doesn't scroll down at all.

Missing cursor after scroll

The problem I have is - after using 'ctrl+d' or 'ctrl+u' the cursor sometimes disappears.
I'm not 100% if that is caused by neoscroll but disabling neoscroll - fixes the issue:

https://user-images.githubusercontent.com/13521338/126875834-f0c16d00-d5f7-4585-8fd8-ea0e35a3896f.mp4
Ignore the view port glitches caused by poor recording software.
Looks like scrolling worked ok 2 days ago, but I do not see any commits that could cause the issue. Maybe somebody can reproduce the issue? I think it is neoscroll that makes the cursor transparent during scroll right?

[Feature Request] Define speed rather than time, or have user defined function to determine time

I work between a very large monitor at work where I have 120+ lines of code and my laptop screen where sometimes I might only have 20-30 lines visible. I've noticed that scrolling up and down feels significantly different between the two situations, mainly because while the time to complete the scroll is the same, the number of lines it moves to do that is different.

It'd be nice to have the option of setting the scroll speed instead of time, as the number of lines needed to do a specific operation changes depending on the window size.

Additionally/alternatively, it'd be really nice to allow for setting a user defined function to determine how long a scrolling operation should take. I'd imagine neoscroll would pass the number of lines for the operation and the function would return the time (in milliseconds) that should be take for the operation.

Uncancellable scroll if pressed for a while

Scroll animation gets stuck/uncancellable if scroll mapping is kept pressed for a while for continuous scroll. It should be able to cancel when user types another key or there's another event.

Centering after animation

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

zz is not centered

A really minor issue but maybe theres a quick fix.

Using zz with nescroll wont result in redrawing the cursor line at the exact center of the window.

The video below shows execution of zz from some postions. With the used zoom level it results in 28 lines above the cursor and 26 below.

neoscroll.1.mp4

Using zz without nescroll results in exact centering - 27 lines above and below the cursor.

Maybe I missed it, but is there already something that allows defining an offset for z commands used with neoscroll?


edit:
I should have checked better before as it is clear when reading the code that one line is added. But I cannot quite follow why the +1 is added. Removing it results in centering the cursorline with zz.

local lines = vim.fn.winline() - math.floor(window_height / 2 + 1)

neoscroll.nvim/lua/neoscroll/init.lua:198: Vim(normal):E471: Argument required: normal!

commit id=4cb8fe7c0e0cbed2fd0852e5ee7f4970359c9650
I open README.txt,
type
I get an error neoscroll.nvim/lua/neoscroll/init.lua:198: Vim(normal):E471: Argument required: normal!

It works well by using commit id=a1c9db5a3dcc900d98bc2efb6c10d3a8b08e42ef

image

My neoscroll config

require('neoscroll').setup({
    mappings = {'<C-u>', '<C-d>', '<C-b>', '<C-f>',
                '<C-y>', '<C-e>', 'zt', 'zz', 'zb'},
    hide_cursor = true,          -- Hide cursor while scrolling
    stop_eof = true,             -- Stop at <EOF> when scrolling downwards
    respect_scrolloff = false,   -- Stop scrolling when the cursor reaches the scrolloff margin of the file
    cursor_scrolls_alone = true, -- The cursor will keep on scrolling even if the window cannot scroll further
    easing = false,              -- easing_function will be used in all scrolling animations with some defaults
    easing_function = function(x) return math.pow(x, 2) end -- default easing function
})

local t = {}
-- Syntax: t[keys] = {function, {function arguments}}
t['<C-u>'] = {'scroll', {'-vim.wo.scroll', 'true', '8'}}
t['<C-d>'] = {'scroll', { 'vim.wo.scroll', 'true', '8'}}
t['<C-b>'] = {'scroll', {'-vim.api.nvim_win_get_height(0)', 'true', '7'}}
t['<C-f>'] = {'scroll', { 'vim.api.nvim_win_get_height(0)', 'true', '7'}}
t['<C-y>'] = {'scroll', {'-0.10', 'false', '20'}}
t['<C-e>'] = {'scroll', { '0.10', 'false', '20'}}
t['zt']    = {'zt', {'7'}}
t['zz']    = {'zz', {'7'}}
t['zb']    = {'zb', {'7'}}

require('neoscroll.config').set_mappings(t)

Cannot unset option 'guicursor'

Hi @karb94
Thank you for this great plugin.
Recently I got a problem.
Here is my reproduce steps.

  1. Start nvim
  2. type :help
  3. type <c-f> got error
    image
  4. type :verbose map <c-f>
    image

nvim version

NVIM v0.6.0-dev+162-g2ae9ff128
Build type: Release
LuaJIT 2.1.0-beta3

neoscroll.nvim version: 54879c6

Some config from my init.vim

set guicursor=
require('neoscroll').setup({
    mappings = {'<C-u>', '<C-d>', '<C-b>', '<C-f>',
                '<C-y>', '<C-e>', 'zt', 'zz', 'zb'},
    hide_cursor = true,          -- Hide cursor while scrolling
    stop_eof = true,             -- Stop at <EOF> when scrolling downwards
    respect_scrolloff = false,   -- Stop scrolling when the cursor reaches the scrolloff margin of the file
    cursor_scrolls_alone = true, -- The cursor will keep on scrolling even if the window cannot scroll further
    easing = false,              -- easing_function will be used in all scrolling animations with some defaults
    easing_function = function(x) return math.pow(x, 2) end -- default easing function
})

local t = {}
-- Syntax: t[keys] = {function, {function arguments}}
t['<C-u>'] = {'scroll', {'-vim.wo.scroll', 'true', '8'}}
t['<C-d>'] = {'scroll', { 'vim.wo.scroll', 'true', '8'}}
t['<C-b>'] = {'scroll', {'-vim.api.nvim_win_get_height(0)', 'true', '7'}}
t['<C-f>'] = {'scroll', { 'vim.api.nvim_win_get_height(0)', 'true', '7'}}
t['<C-y>'] = {'scroll', {'-0.10', 'false', '20'}}
t['<C-e>'] = {'scroll', { '0.10', 'false', '20'}}
t['zt']    = {'zt', {'7'}}
t['zz']    = {'zz', {'7'}}
t['zb']    = {'zb', {'7'}}

require('neoscroll.config').set_mappings(t)

When I disable neoscroll.nvim, I get no error.

If my config or something wrong, please let me know.
Thanks.

Configure the speed of scrolling for all or for one

I am trying to find a way to set the speed of the scrolling from the throw require(...).setup({ time: 100 }), but of course it is not working. After some searching, I found in ./lua/neoscroll/config.lua this code:

https://github.com/karb94/neoscroll.nvim/blob/master/lua/neoscroll/config.lua#L3

There is no way to configure the speed of neoscroll, except by modifying the plugin itself, or by using custom mappings:

https://github.com/karb94/neoscroll.nvim/blob/master/lua/neoscroll/config.lua#L37


I think it is very useful to able some option to control the speed easily, just one option:

require('neoscroll').setup({
      speed = 1.5 -- this will make the scroll x1.5 faster than default
})

bug: enters invalid state when used inside help buffer

Neoscroll config:

require('neoscroll').setup({ })

local mappings = {}
mappings['<C-u>'] = {'scroll', {'-vim.wo.scroll', 'true', '50'}}
mappings['<C-d>'] = {'scroll', {'vim.wo.scroll', 'true', '50'}}
mappings['<C-y>'] = {'scroll', {'-0.10', 'false', '50'}}
mappings['<C-e>'] = {'scroll', {'0.10', 'false', '50'}}
mappings['{'] = {'scroll', {'-0.10', 'true', '50', nil}}
mappings['}'] = {'scroll', {'0.10', 'true', '50', nil}}
mappings['zt'] = {'zt', {'50'}}
mappings['zz'] = {'zz', {'50'}}
mappings['zb'] = {'zb', {'50'}}

require('neoscroll.config').set_mappings(mappings)

Bug: with the given config, when using any of the mappings inside a help buffer, for example the one which opens with the command :help lua, neoscroll outputs the following error message:

E5108: Error executing lua .../pack/packer/start/neoscroll.nvim/lua/neoscroll/init.lua:198: Vim(normal):E471: Argument required: normal! 

Side Effect: cursor becomes invisible after the above mentioned error message in all windows and buffers. neoscroll mappings no longer respond.

C-b and C-f not working

Just installed neoscroll with default settings. <C-d> and <C-u> work really nice but <C-b> and <C-f> doesn't, any idea why that could be? By not working I mean that they do what they are supposed to do but without smooth scrolling.

Looking at :map I see for example:

x  <C-B>       * <Cmd>lua require('neoscroll').scroll(-vim.api.nvim_win_get_height(0), true, 7)<CR>                                                                           
n  <C-B>       * <Cmd>lua require('neoscroll').scroll(-vim.api.nvim_win_get_height(0), true, 7)<CR>                                                                           
...                                                                                                                                      
x  <C-D>       * <Cmd>lua require('neoscroll').scroll(vim.wo.scroll, true, 8)<CR>                                                                                             
n  <C-D>       * <Cmd>lua require('neoscroll').scroll(vim.wo.scroll, true, 8)<CR>                                                                                             
x  <C-E>       * <Cmd>lua require('neoscroll').scroll(0.10, false, 20)<CR>                                                                                                    
n  <C-E>       * <Cmd>lua require('neoscroll').scroll(0.10, false, 20)<CR>                                                                                                    
x  <C-F>       * <Cmd>lua require('neoscroll').scroll(vim.api.nvim_win_get_height(0), true, 7)<CR>                                                                            
n  <C-F>       * <Cmd>lua require('neoscroll').scroll(vim.api.nvim_win_get_height(0), true, 7)<CR>  

Error on neovim startup

I getting an error on neovim startup after install the plugin.

  • Neovim version: NVIM v0.4.4
  • Package manager: vim-plug
  • Startup: init.vim

Here's the error

Error detected while processing  ~/.config/nvim/init.vim:
line    5:
E5105: Error while calling lua chunk: ...onfig/nvim/plugged/neoscroll.nvim/lua/neoscroll/init.lua:8: attempt to call field 'nvim_exec' (a nil value)
Press ENTER or type command to continue

Content in init.vim

call plug#begin()
  Plug 'karb94/neoscroll.nvim'
call plug#end()

lua require('neoscroll').setup()

Support for `{` and `}`

Would love to see this plugins support smooth scrolling for curly braces navigation (which seems to be a popular navigation method for some users).

smooth scroll isnt working

The only error I get is
There are some issues with your config, run :LualineNotices and running that tells me that 'nvim_lsp' is deprecated in favour of 'nvim_diagnostics' and it disappears when I comment neoscroll lines in my config.

My config(.txt format for upload only)
init.txt
neoscroll.txt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.