A Simple Trick for Tinkering in Neovim
March 20, 2024Adding little bits of custom functionality to my Neovim life is one of my favorite things to do. It's just so dang satisfying. Slamming together a little Lua snippet is easy, but the feedback loop of saving, closing Neovim, opening it, and testing it is pretty tedious. Here is a simple trick I use to to iterate faster.
First I created a file inside of my Neovim config lua/jr/custom/playground.lua
vim.api.nvim_create_user_command("RunThing", function(opts)
print("Hello Neovim")
end
Then I created a simple custom keymap
vim.keymap.set("n", "x", function()
-- clear any messages
vim.cmd("messages clear")
-- re-source the file
vim.cmd("luafile ~/.config/nvim/lua/jr/custom/playground.lua")
-- execute the custom command to run the code
vim.cmd("RunThing")
end)
So now I can throw some Lua code together, then test it out by running <leader><leader>x
It's not perfect, but it shortens the feedback loop significantly, which means I can throw together a silly idea the moment it pops into my head.