Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/niuiic/scroll.nvim

Smooth scroll for neovim.
https://github.com/niuiic/scroll.nvim

Last synced: about 2 months ago
JSON representation

Smooth scroll for neovim.

Awesome Lists containing this project

README

        

# scroll.nvim

Smooth scroll for neovim.

- Custom smooth strategy.
- Keep simple, keep reliable.

[More neovim plugins](https://github.com/niuiic/awesome-neovim-plugins)

## Usage

```lua
local keys = {
{
"",
function()
local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get()
local target_lnum = vim.api.nvim_win_get_cursor(0)[1] + screen_h / 2
local step = screen_h / 2 / 50
step = step >= 1 and step or 1

require("scroll").scroll(target_lnum, function(current_line, target_line)
local fold_end = vim.fn.foldclosedend(current_line)

-- if current_line is not in a fold
if fold_end < 0 then
return {
-- cursor position in next step
next_line = current_line + step,
-- delay 10ms for next step
delay = 10,
}
end

local fold_start = vim.fn.foldclosed(current_line)

return {
next_line = fold_end + 1,
delay = 10,
-- when current_line is in a fold, you may want to regard it as one line, then you need to change the target_line
target_line = target_line + fold_end - fold_start,
}
end)
end,
desc = "scroll down",
mode = { "n", "x" },
},
{
"",
function()
local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get()
local target_lnum = vim.api.nvim_win_get_cursor(0)[1] - screen_h / 2
local step = screen_h / 2 / 50
if step < 1 then
step = 1
end

require("scroll").scroll(target_lnum, function(current_line, target_line)
local fold_end = vim.fn.foldclosedend(current_line)
if fold_end > 0 then
local fold_start = vim.fn.foldclosed(current_line)

return {
next_line = fold_start - 1,
delay = 10,
target_line = target_line - fold_end + fold_start,
}
end

return {
next_line = current_line - step,
delay = 10,
}
end)
end,
desc = "scroll up",
mode = { "n", "x" },
},
}
```

## Config

No configuration options available.