From 9f1bce622f1fcd8a2988fa896a76307f57ac42b0 Mon Sep 17 00:00:00 2001 From: robin Date: Tue, 5 May 2026 10:44:32 +0200 Subject: [PATCH] doc: add auto-center example --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/README.md b/README.md index e3733ff..01d2cc4 100644 --- a/README.md +++ b/README.md @@ -33,3 +33,41 @@ vim.g.smoothie_config = { ``` this plugin is inspired by [vim-smoothie](https://github.com/psliwka/vim-smoothie) :) + +## examples + +this example code will automatically center your cursor after 1000 ms of inactivity: + +```lua +local timer = vim.uv.new_timer() +if not timer then + return +end + +local timeout = 1000 +local interval = 20 +local hold = false + +local _timeout = timeout +Smoothie.throttle(function(t) + _timeout = _timeout - t.delta + + if not hold and _timeout <= 0 then + local mode = vim.api.nvim_get_mode().mode + if mode ~= "n" then + return + end + + hold = true + vim.api.nvim_feedkeys("zz", "n", false) + end +end, interval) + +vim.api.nvim_create_autocmd("CursorMoved", { + group = vim.api.nvim_create_augroup("@smoothie.cursormoved", { clear = true }), + callback = function(_) + hold = false + _timeout = timeout + end, +}) +``` -- 2.51.2