Skip to content

Instantly share code, notes, and snippets.

@icholy
Created May 28, 2024 18:27
Show Gist options
  • Save icholy/275a09433be799dc72fb455a6c1d3221 to your computer and use it in GitHub Desktop.
Save icholy/275a09433be799dc72fb455a6c1d3221 to your computer and use it in GitHub Desktop.
--- this shells out to https://llm.datasette.io/en/stable/
vim.api.nvim_create_user_command("LLM", function(opts)
local system = [[
You are a neovim expert.
You help users write commands.
When a user asks a question, your output will be copied directly into the neovim command prompt.
Do not add any explanation.
Since the output is being copied in the command line, it should all be on a single line.
]]
local output = vim.system(
{ "llm", "prompt", "--system", system, opts.args },
{ text = true }
):wait()
if output.code ~= 0 then
vim.notify(output.stderr, vim.log.levels.ERROR)
end
local command = output.stdout
if string.sub(command, 1, 1) ~= ":" then
command = ":" .. command
end
command = string.gsub(command, "\n*$", "")
vim.api.nvim_feedkeys(command, "n", {})
end, { nargs = '?'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment