Created
September 9, 2025 05:21
-
-
Save tomaszkubacki/a0d30c4a42ffdaed481a0e3435caad83 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- 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