Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/niuiic/scroll.nvim
Smooth scroll for neovim.
https://github.com/niuiic/scroll.nvim
neovim plugin smooth-scroll
Last synced: 7 days ago
JSON representation
Smooth scroll for neovim.
- Host: GitHub
- URL: https://github.com/niuiic/scroll.nvim
- Owner: niuiic
- License: mit
- Created: 2024-04-30T00:41:16.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-05-24T08:28:14.000Z (6 months ago)
- Last Synced: 2024-08-02T06:23:54.482Z (3 months ago)
- Topics: neovim, plugin, smooth-scroll
- Language: Lua
- Homepage:
- Size: 6.84 KB
- Stars: 17
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-neovim - niuiic/scroll.nvim - Smooth scrolling, custom smooth strategy. (Scrolling / Treesitter Based)
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 1require("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,
}
endlocal 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
endrequire("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,
}
endreturn {
next_line = current_line - step,
delay = 10,
}
end)
end,
desc = "scroll up",
mode = { "n", "x" },
},
}
```## Config
No configuration options available.