馃 a tiny plugin for smoother movement keybinds
1# 馃 smoothie.nvim
2
3> a tiny plugin for smoother movement keybinds
4
5## requirements
6
7- Neovim `>= 0.12`
8
9## installation
10
11install with `vim.pack`:
12
13```lua
14vim.pack.add({ { src = "https://codeberg.org/comfysage/smoothie.nvim" } })
15```
16
17## usage
18
19smoothie currently on supports smoothing for the `ctrl-d` and `ctrl-u` keybinds.
20
21```lua
22vim.keymap.set("n", "<c-d>", "<plug>(smoothie-ctrl-d)")
23vim.keymap.set("n", "<c-u>", "<plug>(smoothie-ctrl-u)")
24```
25
26you can configure the smoothing settings:
27
28```lua
29vim.g.smoothie_config = {
30 interval = 5,
31 maxtime = 100,
32}
33```
34
35this plugin is inspired by [vim-smoothie](https://github.com/psliwka/vim-smoothie) :)
36
37## examples
38
39this example code will automatically center your cursor after 1000 ms of inactivity:
40
41```lua
42local timer = vim.uv.new_timer()
43if not timer then
44 return
45end
46
47local timeout = 1000
48local interval = 20
49local hold = false
50
51local _timeout = timeout
52Smoothie.throttle(function(t)
53 _timeout = _timeout - t.delta
54
55 if not hold and _timeout <= 0 then
56 local mode = vim.api.nvim_get_mode().mode
57 if mode ~= "n" then
58 return
59 end
60
61 hold = true
62 vim.api.nvim_feedkeys("zz", "n", false)
63 end
64end, interval)
65
66vim.api.nvim_create_autocmd("CursorMoved", {
67 group = vim.api.nvim_create_augroup("@smoothie.cursormoved", { clear = true }),
68 callback = function(_)
69 hold = false
70 _timeout = timeout
71 end,
72})
73```