From f5c9c2d0124f8b0e571d56f52fb8bf55e1792f76 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 3 Sep 2025 12:50:07 +0200 Subject: [PATCH] nvim: Add smartpaste to LLM prompts Will paste and try to integrate _anything_ into the curent buffer. Wrong programming language, no formatting, pseudo code, natural language instructions, anything. --- nvim/.config/nvim/lua/plugins/llm.lua | 72 +++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/nvim/.config/nvim/lua/plugins/llm.lua b/nvim/.config/nvim/lua/plugins/llm.lua index 4f41c36..c9e1894 100644 --- a/nvim/.config/nvim/lua/plugins/llm.lua +++ b/nvim/.config/nvim/lua/plugins/llm.lua @@ -142,6 +142,78 @@ return { }, }, }, + prompt_library = { + + ["Smart Paste"] = { + strategy = "inline", + description = "Paste code smartly", + opts = { short_name = "paste" }, + prompts = { + { + role = "user", + content = [[ +You are a smart code paste agent within Neovim. + +## **Task:** Intelligently integrate content from the user's clipboard into the current buffer. + +## **Instructions:** + +- You may receive code in various programming languages or even natural language instructions. +- If the clipboard content is in a different language than the current buffer, translate it to the appropriate language smartly. +- If the clipboard content contains pseudo code generate code accordingly. +- If the clipboard content contains natural language instructions, interpret and follow them to modify the code in the current buffer. +- **ONLY** generate the **new** lines of code required for seamless integration. +- Ensure the inserted code is syntactically correct and logically consistent with the existing code. +- Do **NOT** include surrounding code or line numbers. +- Make sure all brackets and quotes are closed properly. + +## **Output:** + +- Provide only the necessary lines of code for insertion. +- If you can't generate code just return nothing. +- Ensure the response is proper and well-formatted. + ]], + }, + { + role = "user", + content = function(context) + local lines = require("codecompanion.helpers.actions").get_code( + 1, + context.line_count, + { show_line_numbers = true } + ) + local selection_info = "" + local clipboard = vim.fn.getreg("+") + + if context.is_visual then + selection_info = string.format( + "Currently selected lines: %d-%d", + context.start_line, + context.end_line + ) + else + selection_info = string.format( + "Current cursor line: %d and Current cursor column is %d", + context.cursor_pos[1], + context.cursor_pos[2] + ) + end + + return string.format( + "I have the following code:\n\n```%s\n%s\n```\n\nClipboard content:\n\n```\n%s\n```\n\n%s", + context.filetype, + lines, + clipboard, + selection_info + ) + end, + opts = { + contains_code = true, + }, + }, + }, + }, + }, }, keys = { { "aa", "CodeCompanionActions", desc = "Actions", silent = true, mode = { "n", "v" } },