dotfiles/.config/nvim/lua/discipline.lua
2024-01-02 13:47:10 +01:00

40 lines
855 B
Lua

local M = {}
local max = 5
function M.cowboy()
---@type table?
local id
local ok = true
for _, key in ipairs({ "h", "j", "k", "l", "+", "-" }) do
local count = 0
local timer = assert(vim.loop.new_timer())
local map = key
vim.keymap.set("n", key, function()
if vim.v.count > 0 then
count = 0
end
if count >= max then
ok, id = pcall(vim.notify, "Hold it Cowboy!", vim.log.levels.WARN, {
icon = "🤠",
replace = id,
keep = function()
return count >= max
end,
})
if not ok then
id = nil
return map
end
else
count = count + 1
timer:start(2000, 0, function()
count = 0
end)
return map
end
end, { expr = true, silent = true })
end
end
return M