Skip to content

Instantly share code, notes, and snippets.

@tomaszkubacki
Created September 9, 2025 05:21
Show Gist options
  • Select an option

  • Save tomaszkubacki/a0d30c4a42ffdaed481a0e3435caad83 to your computer and use it in GitHub Desktop.

Select an option

Save tomaszkubacki/a0d30c4a42ffdaed481a0e3435caad83 to your computer and use it in GitHub Desktop.
--- Feed keys into Neovim one by one, simulating a typewriter effect.
--- @param keys string The string to type.
--- @param mode string|nil Feedkeys mode (default "t")
--- @param escape_csi boolean|nil Escape CSI (default false)
--- @param delay_ms number|nil Delay between keystrokes in ms (default 100)
function typewriter(keys, mode, escape_csi, delay_ms)
mode = mode or "t"
escape_csi = escape_csi or false
delay_ms = delay_ms or 100
local i = 1
local len = #keys
local timer = vim.loop.new_timer()
timer:start(0, delay_ms, function()
if i > len then
timer:stop()
timer:close()
return
end
local char = keys:sub(i, i)
vim.schedule(function()
vim.api.nvim_feedkeys(char, mode, escape_csi)
end)
i = i + 1
end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment